0

So I'm learning programming in general, and Ruby specifically; in the course we are developing an app like rottentomatoes.

I need to query the model from the controller, to render in the view the distinct values in that specific column.

I have this piece of haml to embed the result on the template:

  = form_tag movies_path, :method => :get do
    Include:
    - @all_ratings.each do |rating|
      = rating
      = check_box_tag "ratings[#{rating}]"
    = submit_tag 'Refresh'

I have @all_ratings in the controller, I have tried movie[attr_rating] , Movie(:rating)... And I don't know what else to throw to it.

I do not want to hardcode the values (['G','PG','PG-13','R']) in the controller, but learn how to query the model.

cerealCode
  • 35
  • 6
  • 1
    You cannot query a column for all its "possible" values, that makes no sense. Are you trying to query a *validation* for the values it will allow? Or are you using an [enum](http://edgeapi.rubyonrails.org/classes/ActiveRecord/Enum.html) to get the possible values for that? Or do you just want to get the distinct values for a column? You need to include some code to show us what it is you're trying to do. We can't help you without at least *some* information about the column and model. – user229044 Jun 28 '16 at 19:41
  • Sorry for the poor explanation. I want to get the distinct values for a column. – cerealCode Jun 28 '16 at 19:46
  • Then your question has been well answered in the linked duplicate. – user229044 Jun 28 '16 at 19:48
  • Thanks, I'm still earningl to search for answers – cerealCode Jun 28 '16 at 19:52

0 Answers0