views:

37

answers:

2

In the controller, I'd like to do:

@options = { :obj_id => @obj.id, :obj2_id => @obj2.id }

And in the view:

<%=
remote_form_for(:model_object, :url => { :action => 'some_action' }) do |f|
     @options.each { |k, v|
       f.hidden_field(k, { :value => v })
     }
}
%>

The code above currently will just output the string values of each key/value and not a hidden input field.

My experience tells me I'm missing something simple... What am I missing?

Thanks for the help.

A: 

Right after I posted the question and thought about it more thoroughly (and with some luck), I found the object.send function. The following code resolves my issue:

In the controller:

@options = { :obj_id => @obj.id, :obj2_id => @obj2.id }

In the view:

 <% remote_form_for(:model_object, :url => { :action => 'some_action' }) do |f| %>
      <% @options.each { |k, v| %>
        <%= f.send :hidden_field, k, { :value => v } %>
      <% } %>
 }
 %>
pglombardo
A: 

You don't need to use send for this because hidden_field isn't a private method, nor is the method you're calling dynamic. These are the only two reasons you should be using send.

Instead, make your form use more ERB tags:

<%= remote_form_for(:model_object, :url => { :action => 'some_action' }) do |f| %>
  <% @options.each do |k, v| %>
    <%= f.hidden_field(k, { :value => v }) %>
  <% end %>
<% end %>
Ryan Bigg