JP Silvashy
JP Silvashy

Reputation: 48475

Trouble with rails hidden fields

I'm a little confused on how hidden form fields work in Rails, like for example I have two hidden fields in my form like so:

(for a polymorphic model for commenting)

<%= form_for [commentable, commentable.comments.build], :remote => 'true' do |form| %>
  <%= hidden_field "resource", commentable.class.to_s.downcase %>
  <%= hidden_field "resource_id", commentable.id %>

  <%= form.text_area :body %>
  <%= submit_tag 'Post comment' %>
<% end %>

But so this works fine and what not, but the params that I receive in my controller are like this:

"resource"=>"photos", "resource_id"=>{"174"=>""}

Why is my resource_id param a hash too?

Upvotes: 0

Views: 630

Answers (2)

DGM
DGM

Reputation: 26979

This doesn't answer the question directly, but... Take out the resource_id and look in your params in the log file, I think the id is already passed in the url because of the path you provide in the form_for call

Upvotes: 0

Hugh Bothwell
Hugh Bothwell

Reputation: 56624

<%= hidden_field "resource_id", commentable.id.keys[0] %>

A better question would be, where and how are you assigning the id?

Upvotes: 3

Related Questions