开发者

Trouble with rails hidden fields

开发者 https://www.devze.com 2023-02-02 15:29 出处:网络
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:

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?


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

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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消