ruby-on-rails-3

Simple Search Form in Rails 3 App not Displaying

六月ゝ 毕业季﹏ 提交于 2020-01-14 03:49:07
问题 I ran through railscast #37 and can't seem to even get my search form to display on my index page. Any ideas whats wrong with my code? thanks in advance! any help is greatly appreciated. Here is the index page where the form is located: <h1>All users</h1> <% form_tag users_path, :method => 'get' do %> <p> <%= text_field_tag :search, params[:search] %> <%= submit_tag "Search", :name => nil %> </p> <% end %> Heres the controller: class UsersController < ApplicationController ... def index

Can't suppress output in nested block helper in rails 3

梦想与她 提交于 2020-01-14 03:07:11
问题 This one is sort of twisting my noodle. I have something resembling this (in a rails 3 engine if that matters) class Builder def initialize @foos = [] end def foo(&block) @foos << helper.capture(&block) #helper being a class that is including ActionView::Helpers end def to_html @foos.join "\n" end end module ApplicationHelper def widget b = Builder.new yield b b.to_html end end #in a view somewhere <%= widget do |b| %> <% b.foo do %> static content <% end %> <% end %> Everything is working

Want to load seed data before running cucumber

淺唱寂寞╮ 提交于 2020-01-14 02:57:08
问题 I want cucumber to load my seed data in "db/seeds.rb" before starting to test. Not before each scenario or feature, but only once before running the tests. And also after each scenario, the seeds must remain in db. Is that possible? I've tried creating a file "features/support/seed_data.rb" and requiring my db/seeds.rb in there, but it seems that file is not loaded at all. I tried to require my seeds in env.rb - no affect. Please, can anybody suggest me the solution? Thanks in advance! 回答1:

How can I pass an object to rabl views from rake task

吃可爱长大的小学妹 提交于 2020-01-14 02:46:26
问题 I am trying to create a json file from a rake task using rabl. Below I have the simplified version to test with. When I view 'articles.json' or 'articles/2.json' via the url, I get the expected json response. But when I try to run it via the rake task, it always has a null value for @articles in the jsonFile created. It will render the index.json.rabl view the same number of times as @articles.count, but the values are always null. So how do I pass in the @articles object created in my rake

Rails building a Serialized object of N records

僤鯓⒐⒋嵵緔 提交于 2020-01-14 02:46:12
问题 I want to serialize any object(s) in text columns. Via an API, I get the params: params[:attachments] -- this can be 0 or 1 or 3, or 100+ etc... params[:attachment1]...params[:attachment2] ... params[:attachmentN] So how do I store X # of attachments in a serialized object? mailThing = MailThing.create(:attachments => myAttachmentsSerizliedIfANY ) I'm trying to do: @myAttachmentsSerizliedIfANY = nil i = 0 attachmentCount = params[:attachments].to_i while i < attachmentCount do

Use two different databases in one project

混江龙づ霸主 提交于 2020-01-14 01:41:07
问题 Is it possible to use two different databases for the same project in Ruby On Rails? At the moment I use PostgreSQL with Heroku for my project and I would like to use Redis to store some of my models. Thanks First step, add redis-rb to your Gemfile: gem 'redis', '2.1.1' Then install the gem via Bundler: bundle install Lastly, create an initializer in config/initializers/redis.rb and add the following: $redis = Redis.new(:host => 'localhost', :port => 6379) Will that have any side effects to

Cannot modify association because the source reflection class is associated to via :has_many + rails 3.0.10

时光总嘲笑我的痴心妄想 提交于 2020-01-13 22:40:13
问题 Getting Following Error ActiveRecord::HasManyThroughCantAssociateThroughHasOneOrManyReflection in ProjectController#create Cannot modify association 'ProjectMaster#tag_masters' because the source reflection class 'TagMaster' is associated to 'ProjectTag' via :has_many. Following are my models. class ProjectTag < ActiveRecord::Base has_many :tag_masters has_many :project_masters end class TagMaster < ActiveRecord::Base has_many :project_tags has_many :project_masters, :through => :project_tags

Implementing Observer Pattern for my Rails App

柔情痞子 提交于 2020-01-13 19:32:06
问题 I am currently using rails 3.0.7 and ruby 1.9.2 and making a rails App which contains a video being loaded from a database while being rendered by FlowPlayer. and a set of slides based on the video. Now, I wanted to synchronize the slides with the video. For the timings, I am asking the user to enter the timings of each slide. So, I was wondering if i could use observer pattern for this by making a sort of central time as the subject and the video and slides as the observers? While, the

Rails 3 using MongoDB via mongoid adapter - is there any way to share attribute specifications without using Single-Table Inheritance?

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-13 18:20:07
问题 Probably a confusing title, but not sure how else to put it. Example should make it clearer. I have many different models that share many of the same attributes. So in each model I have to specify those same attributes and THEN the attributes that are specific to that particular model. Is there any way I can create some class that lists these basic attributes and then inherit from that class without using Single-Table Inheritance? Because if I put all the shared attributes and Mongoid

Persistent Ruby segfaulting after a clean install

橙三吉。 提交于 2020-01-13 14:05:21
问题 Ruby keeps segfaulting when using the Koala gem to talk over HTTP: /Users/pawel/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/net/http.rb:799: [BUG] Segmentation fault I've tried the following: Run which -a ruby which showed multiple Rubies via MacPorts. So I deleted those and running the same command again returns only /usr/bin/ruby I've removed the MacPorts version of PostgreSQL and installed it with Homebrew instead (With MacPorts, it installs its own version of OpenSSL) Running openssl version