开发者

Ruby on Rails - How to pass hash parameter to a partial view?

'shared/subscription' %>

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 %>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜