Providing partial data from a helper method

Is it possible to make partial use of a helper method in which you can also pass local variables from the view in which the helper method is called? For example, when I include this code directly in the view, it does partial correctly:

<%= render :partial => "add_round", :locals => { :f => f } %> 

Then I translated it into a helper method:

 def addRound render :partial => "add_round", :locals => { :f => f } end 

Then I called it again from the view:

  <%= addRound %> 

This did not work with: locals => {: f => f} included in the code. He returned this error: undefined local variable or `f 'method. However, the addRound method did something with the following:

 def addRound render :partial => "add_round" end 

Writing this method allowed me to display partial ones that did not require the transfer of local variables (for example, simple text strings). But how can I make it work with: locals => {: f => f} enabled? Is there any other way to write this?

Many thanks.

+8
ruby-on-rails
source share
1 answer

You need to pass f to addRound

 def addRound(f) render partial: "add_round", locals: { f: f } end 

and in the presentation

 <%= addRound(f) %> 
+13
source share

All Articles