ruby-on-rails-3

Rails - Railscasts nested complex forms

夙愿已清 提交于 2020-01-06 14:33:48
问题 I am using Ryan Bates' Complex Forms Deep Branch, and trying to replicate that example for a form that has two additional nested levels. SurveyName has many SurveyQuestions, which have many SurveyOptions. # application_helper (identical to deep branch) def remove_child_link(name, f) f.hidden_field(:_destroy) + link_to_function(name, "remove_fields(this)") end def add_child_link(name, f, method) fields = new_child_fields(f, method) link_to_function(name, h("insert_fields(this, \"#{method}\", \

Ruby 1.92 in Rails 3: A Case where Array.length Does Not Equal Array.count?

拜拜、爱过 提交于 2020-01-06 14:17:14
问题 My understanding is that count and length should return the same number for Ruby arrays. So I can't figure out what is going on here (FactoryGirl is set to create--save to database--by default): f = Factory(:family) # Also creates one dependent member f.members.count # => 1 f.members.length # => 1 m = Factory(:member, :family=>f, :first_name=>'Sam') #Create a 2nd family member f.members.count # => 2 f.members.length # => 1 puts f.members # prints a single member, the one created in the first

Rspec error when I run my rspec test of my controller

独自空忆成欢 提交于 2020-01-06 14:10:57
问题 I am developing a Rails v2.3 application. When I run the rspec test by execute command: rspec spec/controllers/my_controller_spec.rb I got the error message which is showing below: /.rvm/gems/ruby-1.8.7-p352@myapp/gems/rspec-core-2.6.4/lib/rspec/core/configuration.rb:427:in `raise_if_rspec_1_is_loaded': (RuntimeError) ******************************************************************************** You are running rspec-2, but it seems as though rspec-1 has been loaded as well. This is likely

Deleting nested objects

跟風遠走 提交于 2020-01-06 14:01:17
问题 I have a profile, and this profile has many curso s (courses). I show all the courses a profile has on the show.html.erb of this profile. <% for curso in @profile.cursos %> <li><%=h curso.nome %> - <%=h curso.universidade %><br> Ingresso em: <%=h curso.ano_ingresso %> - Encerra em: <%=h curso.ano_termino %> <li> <%= button_to 'Delete', { :action => "destroy", :id => curso.id },:confirm => "Are you sure?", :method => :delete %> This way, I'm able to show all the courses a profile has on it's

Paper_trail with accepts_nested_attributes_for

你离开我真会死。 提交于 2020-01-06 13:51:55
问题 I have a rails app that has articles that and the user can add links and reviews as nested attributes. I saw in the paper_trail https://github.com/airblade/paper_trail/ documentation that this is not covered by that gem. How would I go about setting up undo functionality so that nested attributes or has_many associations are restored/updated when a user clicks undo? 回答1: I think if you hook in a "destroy" post to the undo button it will at least remove the links if they click undo. Basically

Rails :ActionView::Template::Error (undefined method `model_name' for NilClass:Class): [duplicate]

天涯浪子 提交于 2020-01-06 12:56:44
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: MetaSearch “undefined method `model_name' for NilClass:Class” for global bar search This is the error I'm getting using my updated code when I try going to a user's profile or a individual posts (/posts/1). Its weird that its trying to access the unlike partial anyway because its a new user without any likes. I've got the code exactly as it shows in the tutorial I used to do this with following users. It works

Facebook fb-login not redirecting back

房东的猫 提交于 2020-01-06 12:54:31
问题 I want to authenticate the user using facebook login credentials. Everything works, except for the fact that it does not redirect to the redirect_uri specified which I require to capture the signed_request. Any help is hugely appreciated. Below is what I have #fb-root %script{:src => "http://connect.facebook.net/en_US/all.js"} :javascript FB.init({ appId:'my_client_id_from_the_app_i_created', cookie:true, status:true, xfbml:true }); %fb:login-button{:perms => "publish_stream", :redirect_uri =

Rails help with building Admin area - Routing problem

佐手、 提交于 2020-01-06 12:51:10
问题 I am making a Admin area. In app/controllers application_controller.rb public_controller.rb admin_controller.rb kategoris_controller.rb And in app/controllers/admin kategoris_controller.rb My route file: resources :kategoris namespace :admin do resources :kategoris end My kategori index file in app/views/admin/kategories/index <h1>Listing kategoris</h1> <table> <tr> <th>Navn</th> <th></th> <th></th> <th></th> </tr> <% @kategoris.each do |kategori| %> <tr> <td><%= kategori.name %></td> <td><%=

Rails help with building Admin area - Routing problem

本小妞迷上赌 提交于 2020-01-06 12:51:08
问题 I am making a Admin area. In app/controllers application_controller.rb public_controller.rb admin_controller.rb kategoris_controller.rb And in app/controllers/admin kategoris_controller.rb My route file: resources :kategoris namespace :admin do resources :kategoris end My kategori index file in app/views/admin/kategories/index <h1>Listing kategoris</h1> <table> <tr> <th>Navn</th> <th></th> <th></th> <th></th> </tr> <% @kategoris.each do |kategori| %> <tr> <td><%= kategori.name %></td> <td><%=

RnR: Database normalization, rails models and associations

末鹿安然 提交于 2020-01-06 12:23:41
问题 Ok, so I have three different objects: a person, place, and equipment. Each can have an address, in most cases multiple address and multiple phone numbers. So my thought is create the specific object tables, the have an address and a phone table. Here my question: So typically, in my SQL world, I would just have an object_id column in the address and phone table and put a id of the object in the object id column, and then select all the address or phone records that match. I could do this, do