Q:

Passing an object through form_tag post Ruby on Rails

I am relatively new to rails. I am using a partial like a ui component, to call certain controllers. Here is something that I have in shared/post_button.html.erb and I pass in params while rendering the partial, like controller and action OR the path.
<%
path = "" if !path 
action = "" if !action 
controller = "" if !controller 
values = {} if !values
%>
<%= form_tag(path, :controller => controller, :action => action, :method => "post") do %>
    <%= hidden_field_tag(:values, values) %>
    <%= submit_tag label %>
<% end %>

I am using this way to call certain controllers via POST using a form (instead of a link_to passing variables) because I figured that was a more secure way of posting certain records in to the DB. Comments welcome to let me know if there is a better method or syntax to go about doing this.
Now, my question is: What I am trying to do here is have an ability to pass in a values object containing all sorts of values I'd like to receive at the controller end. At the moment, the values tag doesn't seem to work. How do I go about passing in objects/values to the controller? Do I need to append it to the URL? The way I am using this partial, I sometimes do not pass in the url and pass in a controller and action variable, how would I go about passing values then?

A:

Are you looking for something like this? 
<%= form_tag(path, :controller => controller, :action => action, :method => "post") do %>
    <% values.each_pair do |k,v| %>
      <%= hidden_field_tag(k, v) %>
    <% end %>
    <%= submit_tag label %>
<% end %>

Where you iterate over each key/value pair in your values hash to submit them as individual parameters.

