{:f => f}

Subscribe to {:f => f} 2 post(s), 2 voice(s)

 
Avatar Roupen 84 post(s)

The views in this Exercisr, such as on p119, has {:f => f} in several places that I’m not familiar with. What does it mean? Thanks.

 
Avatar EldonAlameda Administrator 196 post(s)

okay – hopefully i can explain this so it makes sense.

What we’re doing in those examples is passing a value from the calling template to the partial (so that they will be available in the partial)

<%= render :partial => 'form', :locals => {:f => f} %>

So in the example – we’re passing whatever f represents within the calling template to the partial in the :f symbol in this format
:locals => {:name_in_partial => name_here_in_template}

So in these examples – our form is being built in a block i.e.

<% form_for(:exercise, :url => exercises_path) do |f| %>

When we create our forms in a block like this – it means we can use the f variable to build all our fields

f.text_field :name

but we can’t do that in the partial unless we pass that f variable to it as a local variable. So that’s what I’m doing there. I’m making that form block variable f available to the partial so we can use it to create our fields within the partial.

Does that help make sense?