0bserver07
0bserver07

Reputation: 3471

Rails: can't pass variable to partial, what am I doing wrong?

I'm trying a few different ways to define and pass the local variable to the partial, but it keeps saying it's undefined:

in Show file:

<% @startups.each do |startup| %>
  <%= render :partial => "profile/startup" %>
<% end %>

in partial:

<%= simple_form_for [@commentable, @comment], :remote => true do |form| %>
  <%= form.input :content, label: false, :input_html => { :id => "#{startup.user_id}" } %>
  <%= form.submit "Submit" %>
<% end %>

These are the other ways I'm trying to pass the variable, but still getting undefined:

<%= render :partial => "user_comments/uac",  object: startup, as: startup %>
<%= render :partial => "user_comments/uac",  collection: startup, as: startup %>
<%= render :partial => "user_comments/uac", :locals => {:startup => startup} %>

Upvotes: 1

Views: 1661

Answers (1)

user229044
user229044

Reputation: 239551

Get rid of :partial. You haven't needed that in Rails for several versions.

The correct way of passing a local called startup to a partial is this:

render "profile/startup", startup: startup

Upvotes: 8

Related Questions