3

I'm able to pass a single argument from a view to a partial, but for some reason when I add a second it is undefined (nil class).

Here's how I call the partial in the view:

<%= render 'project_form', locals: {project: @project, form_method: 'patch'} %>

Here's the top of the partial (_project_form.html.erb):

<%= logger.debug( @form_method ) %>

This prints "true" in the view, and logs nothing (a blank line) in the log.

Why isn't it receiving the second argument? I can debug @project and it's the class I expect.

Update: According to this question, you need to modify the render syntax slightly to pass multiple arguments.

So I had two problems: 1) the variable scope, 2) the render :partial syntax needs to be explicit to pass more than one local variable.

Community
  • 1
  • 1
emersonthis
  • 32,822
  • 59
  • 210
  • 375
  • if @project is working then it probably means you dont even need to pass it (since it's an instance variable and already available) – Tom Prats Sep 18 '13 at 13:48

1 Answers1

2

Its a local variable you are trying to print. Try this in your partial instead of @form_method:

<%= logger.debug( form_method ) %>

and I think the below will print value in your partial :

<%= form_method %>
Rails Guy
  • 3,836
  • 1
  • 20
  • 18
  • 1
    Thanks. That seems to work. Can you help me understand why @project was defined? Does the scope of the instance variable apply automatically into the partial? – emersonthis Sep 18 '13 at 13:50
  • Yes, the @project scope will automatically applied into all the partials, that you will render into your view. – Rails Guy Sep 18 '13 at 13:53