Felix
Felix

Reputation: 5619

rails partial passing param got empty variable

I try to pass a param to a partial in view

controller

def addMovie
  @movies = Movie.all
  @vid = Movie.new
end

view

<%= render partial: "shared/videoList", videoList: :movies %>

partial stored in app/views/sharead

<% if @videoList.present? %>
    <% @videoList.each do |movie| %>

videoList is empty ... why?

Upvotes: 0

Views: 94

Answers (1)

Rajdeep Singh
Rajdeep Singh

Reputation: 17834

Access the variable using videoList and not @videoList,

<% if videoList.present? %>
    <% videoList.each do |movie| %>

also, you need to pass the variable like this

<%= render 'shared/videoList', videoList: @movies %>

Hope that helps!

Upvotes: 4

Related Questions