0

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?

2
  • try render 'shared/videoList', :locals => { videoList: @movies} Commented Mar 15, 2016 at 11:33
  • problem is that '@movies' is empty. ... I tried <%= Movie.all.inspect %> in view ... works fine ... but the @movies is empty ... Commented Mar 17, 2016 at 22:57

1 Answer 1

4

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!

Sign up to request clarification or add additional context in comments.

4 Comments

thanks. but then I got this error: 'undefined local variable or method `videoList' for'
but in database there are entries
Check if the @movies variable is empty or not!
problem is that '@movies' is empty. ... I tried <%= Movie.all.inspect %> in view ... works fine ... but the @movies is empty ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.