emersonthis
emersonthis

Reputation: 33378

Rails 4: passing multiple arguments to partial

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.

Upvotes: 3

Views: 3046

Answers (1)

Rails Guy
Rails Guy

Reputation: 3866

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

Upvotes: 2

Related Questions