views:

41

answers:

1

Hi, I use this:

<%= render :partial => 'shared/subscription' %>

To 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 %>
+3  A: 
<%= render :partial => "shared/subscription", :locals => {:foo => "bar", :foofoo => ["bar", "bar"]}

In your partial view, use them:

<%= foo #this outputs "bar" %>
<%= foofoo.to_s %>
PeterWong
`@foo` or just `foo`? I suppose that just `foo`.
floatless
You are right, I'll edit it ;D
PeterWong
Thanks but I tried to retrieve the variable using `<% form_for(:subscription, :url => city_subscriptions_path(@city), :html => {:id => @form_id} ) do |form| %>`but it doesn't work.
Khairul
so you want to pass form_id into the form from outside the partial? `render :partial => "something", :locals => {:form_id => "abc"}` and `form_for (:subscription, :url => city_subscriptions_path(@city), :html => {:id => form_id } ) do |form|`
PeterWong