Skip to content

Instantly share code, notes, and snippets.

@rbatta
Created July 28, 2013 14:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rbatta/6098832 to your computer and use it in GitHub Desktop.
Save rbatta/6098832 to your computer and use it in GitHub Desktop.
in movies_controller.rb under def index
debugger
@all_ratings = Movie.all_ratings
# checked_box = params[:rating]
if params[:commit] == "Refresh"
checked_box = params[:ratings] # params[:ratings] is a hash!
checked_box.map do |x,y|
@all_ratings = Movie.all_ratings
Movie.find_all_by_rating(x)
end
else
@movies = Movie.order(params[:sort_by])
end
----------
in rails server --debugger mode stepping thru and eval Movie.find_all_by_rating(x) gives:
(rdb:2) n
/home/ubuntu/Documents/hw2_rottenpotatoes/app/controllers/movies_controller.rb:29
Movie.find_all_by_rating(x)
(rdb:2) eval Movie.find_all_by_rating(x)
[#<Movie id: 1, title: "Aladdin", rating: "G", description: nil, release_date: "1992-11-25 00:00:00", created_at: "2013-07-23 19:47:39", updated_at: "2013-07-23 19:47:39">, #<Movie id: 7, title: "2001: A Space Odyssey", rating: "G", description: nil, release_date: "1968-04-06 00:00:00", created_at: "2013-07-23 19:47:39", updated_at: "2013-07-23 19:47:39">, #<Movie id: 10, title: "Chicken Run", rating: "G", description: nil, release_date: "2000-06-21 00:00:00", created_at: "2013-07-23 19:47:39", updated_at: "2013-07-23 19:47:39">]
(rdb:2) n
/home/ubuntu/Documents/hw2_rottenpotatoes/app/controllers/movies_controller.rb:29
Movie.find_all_by_rating(x)
(rdb:2) eval Movie.find_all_by_rating(x)
[#<Movie id: 8, title: "The Incredibles", rating: "PG", description: nil, release_date: "2004-11-05 00:00:00", created_at: "2013-07-23 19:47:39", updated_at: "2013-07-23 19:47:39">, #<Movie id: 9, title: "Raiders of the Lost Ark", rating: "PG", description: nil, release_date: "1981-06-12 00:00:00", created_at: "2013-07-23 19:47:39", updated_at: "2013-07-23 19:47:39">]
(rdb:2)
---------
in rails console Movie.find_all_by_rating(x) gives this:
irb(main):014:0> checked_box = {"G"=>"1", "PG"=>"1"}
=> {"G"=>"1", "PG"=>"1"}
irb(main):015:0> checked_box.map {|k,v| Movie.find_all_by_rating(k)}
Movie Load (0.2ms) SELECT "movies".* FROM "movies" WHERE "movies"."rating" = 'G'
Movie Load (0.1ms) SELECT "movies".* FROM "movies" WHERE "movies"."rating" = 'PG'
=> [[#<Movie id: 1, title: "Aladdin", rating: "G", description: nil, release_date: "1992-11-25 00:00:00", created_at: "2013-07-23 19:47:39", updated_at: "2013-07-23 19:47:39">, #<Movie id: 7, title: "2001: A Space Odyssey", rating: "G", description: nil, release_date: "1968-04-06 00:00:00", created_at: "2013-07-23 19:47:39", updated_at: "2013-07-23 19:47:39">, #<Movie id: 10, title: "Chicken Run", rating: "G", description: nil, release_date: "2000-06-21 00:00:00", created_at: "2013-07-23 19:47:39", updated_at: "2013-07-23 19:47:39">], [#<Movie id: 8, title: "The Incredibles", rating: "PG", description: nil, release_date: "2004-11-05 00:00:00", created_at: "2013-07-23 19:47:39", updated_at: "2013-07-23 19:47:39">, #<Movie id: 9, title: "Raiders of the Lost Ark", rating: "PG", description: nil, release_date: "1981-06-12 00:00:00", created_at: "2013-07-23 19:47:39", updated_at: "2013-07-23 19:47:39">]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment