Ruby on Rails - How to pass hash parameter to a partial view?
To c开发者_如何学Call this partial view:
<% form_for(:subscription, :url => city_subscriptions_path(@city)) do |form| %>
<%= form.hidden_field :city_id, :value => @city.id %>
<%= form.text_field :email, :size => 30 %>
<%= form.submit "Email Me" %>
<% end %>
Since I am using this partial view on different places, how do I alter the caller so it will pass a hash for the form_for
helper? So it would be like this when the helper is called:
<% form_for(:subscription, :url => city_subscriptions_path(@city), :html => {:id => 'main_input' }) do |form| %>
<%= form.hidden_field :city_id, :value => @city.id %>
<%= form.text_field :email, :size => 30 %>
<%= form.submit "Email Me" %>
<% end %>
<%= render :partial => "shared/subscription", :locals => {:foo => "bar", :foofoo => ["bar", "bar"]}
In your partial view, use them:
<%= foo #this outputs "bar" %>
<%= foofoo.to_s %>
精彩评论