On Sun, Oct 21, 2012 at 10:20 AM, Muhammad Salman <li...@ruby-forum.com> 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

if !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@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to