Ruby on Rails Sunday, August 2, 2015

fields_for is a devil to understand, with and without a parent/data form.  You need to really study the Rails documentation a lot, create scenarios from your data....  Before you try fields_for you should test at 'rails console' for certainty that your associations are productive.   Be certain of your data before testing because association testing in true null/empty is pretty nondescript... If you are bold, go to GitHub, and search to Rails applications and then fields_for....

Best to you.

Liz

PS: Write to Colin Law, he is a wealth of information regarding tutorials...



On Sunday, August 2, 2015 at 7:15:48 PM UTC-4, Bazley wrote:
You were right, it looks like it's active_comment_relationship is nil, I think. I added the yaml line and got this:

--- !ruby/hash:ActionController::Parameters

utf8: ✓

authenticity_token: nNWNdGOzKSu5gfDkB4x3AFIO1PQnIggn65uE//SGQNzK8Ub5AOtsShH3CLZd+oU7ic9WlA+F0RbsSVR6X1I78w==

callsign: bazzer

notice: !ruby/hash:ActionController::Parameters

  latitude: '51.75253980933651'

  longitude: '-1.39801025390625'

  content: Hello everyone

commit: Drop

controller: notices

action: create

Completed 500 Internal Server Error in 31ms (ActiveRecord: 7.1ms)

NoMethodError (undefined method `[]' for nil:NilClass):


I have updated my code to use a form builder. It's all working great except for this one problem. The code is below. For some reason the fields_for is not working - as the params above shows there should be an active_comment_relationship parameter for notice but it isn't present. What's wrong with this code?:


    <%= form_for(:notice, url: :notices, method: :post, html: { multipart: true, class: "comment_form" } ) do |f| %>
     
<%= hidden_field_tag :callsign, @character.callsign %>
     
<%= f.fields_for :active_comment_relationship do |ff| %>
       
<%= ff.label :commentee_id %>
       
<%= ff.hidden_field :commentee_id, value: notice.id %>
     
<% end %>
     
<%= f.hidden_field :latitude,  value: notice.latitude,  id: "comment_notice_latitude"  %>
     
<%= f.hidden_field :longitude, value: notice.longitude, id: "comment_notice_longitude" %>
     
<%= f.text_area :content, rows: 1, id: "commentField-#{notice.id}", class: "comment_area" %>
     
<%= f.submit( "Post", class: 'btn btn-default btn-xs',
                    onclick
: "return validateCommentForm('#commentField-#{notice.id}');" ) do %>
       
<span class="glyphicon glyphicon-ok" aria-hidden="true"></span>
     
<% end %>
     
<%= f.file_field :picture, accept: 'image/jpeg,image/gif,image/png' %>
   
<% end %>





--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/fd00575e-ca50-4017-91e2-371f31f02d96%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment