This is the code if !params[:ratings].nil? params[:ratings].each_key do |r| @selected_ratings << r @movies << Movie.where(''rating = :rating'', :rating => r) @sort = params[:sort] end elsif @selected_ratings = @all_ratings @movies = Movie.order(@sort) @sort = params[:sort] end This is the error You have a nil object when you didn''t expect it! You might have expected an instance of Array. The error occurred while evaluating nil.<< -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
On 21 October 2012 16:20, Muhammad Salman <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> This is the code > > if !params[:ratings].nil? > params[:ratings].each_key do |r| > @selected_ratings << r > @movies << Movie.where(''rating = :rating'', :rating => r) > @sort = params[:sort] > end > elsif > @selected_ratings = @all_ratings > @movies = Movie.order(@sort) > @sort = params[:sort] > end > > This is the error > > You have a nil object when you didn''t expect it! > You might have expected an instance of Array. > The error occurred while evaluating nil.<<The clue is often in the error message, it is worth reading it carefully. It is saying that you have something << where the something is nil. You have not told us which line it is failing on, but presumably it is either @selected_ratings or @movies. What are they set to before the lines you have shown us? Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
On Sun, Oct 21, 2012 at 10:20 AM, Muhammad Salman <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> This is the code > > if !params[:ratings].nil? > params[:ratings].each_key do |r| > @selected_ratings << r > @movies << Movie.where(''rating = :rating'', :rating => r) > @sort = params[:sort] > end > elsif > @selected_ratings = @all_ratings > @movies = Movie.order(@sort) > @sort = params[:sort] > endif !params[:ratings].blank? && params[:ratings].is_a?(Array) params[:ratings].each do |rating| (@selected_ratings ||= []) << rating @sort = params[:sort] (@movies ||= []) << Movie.where("rating = ?", rating) end else @selected_ratings = @all_ratings @sort = params[:sort] @movies = Movies.order(@sort) end -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Hi, Maybe i should explained a bit more about the problem. So the thing is that that i have a movie table in the database with properties such as titile, rating etc. Now i have a check box of ratings like [''G'',''PG'',''R'']. When a user selects one or more of these check boxes then i have those in my params[ratings]. For example if he chooses ''R'' and ''G'' then my params[rating] would be [''G'', ''R'']. Now, what i want to do is to have only those movies which have the following ratings in my @movies and for that i am trying to use @movies << Movie.where(''rating = :rating'', :rating => r) but it fails I have tried to use @movies = Movie.where(''rating = :rating'', :rating => r) But in this case i have movies selected with respect to one particular rating for example only ''R'' rated movies are shown. Also i cannot do @movies = [] because i have movies with properties such as title etc... One more thing to add, i am new to web and database related stuff :) -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
On 21 October 2012 17:04, Muhammad Salman <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hi,Since you have not quoted the previous reply we do not know whether this is in reply to Jordan''s suggestion. If it is in reply to his suggestion then you should quote it and make clear why it does not work. Colin> > Maybe i should explained a bit more about the problem. So the thing is > that that i have a movie table in the database with properties such as > titile, rating etc. Now i have a check box of ratings like > [''G'',''PG'',''R'']. When a user selects one or more of these check boxes > then i have those in my params[ratings]. For example if he chooses ''R'' > and ''G'' then my params[rating] would be [''G'', ''R'']. Now, what i want to > do is to have only those movies which have the following ratings in my > @movies and for that i am trying to use > > @movies << Movie.where(''rating = :rating'', :rating => r) > > but it fails > I have tried to use > > @movies = Movie.where(''rating = :rating'', :rating => r) > > But in this case i have movies selected with respect to one particular > rating for example only ''R'' rated movies are shown. > > Also i cannot do @movies = [] > because i have movies with properties such as title etc... > > One more thing to add, i am new to web and database related stuff :) > > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit https://groups.google.com/groups/opt_out. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Colin Law wrote in post #1080610:> On 21 October 2012 17:04, Muhammad Salman <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> Hi, > > Since you have not quoted the previous reply we do not know whether > this is in reply to Jordan''s suggestion. If it is in reply to his > suggestion then you should quote it and make clear why it does not > work. > > ColinMy previous reply was not in reply to Jordans suggestions it was description of my original problem which i later realized requires description. Since i cannot edit my original question any more so had to do it in middle of the thread -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.