ruby on rails - Learning RoR first project CS169 edX -
i'm working on second homework, reference completed version http://alexandre-alcobia.herokuapp.com/movies can't seem "movie title" , "release date" headers become links. kind of think there's wrong view file, i'm including relevant portion of controller because when manually include ?sort=title end of uri doesn't end sorted.
here's moviescontroller.rb
class moviescontroller < applicationcontroller ... def index @movies = movie.all unless params["sort"] == nil @movies = movie.order('movies.title').all if params["sort"] == "title" @movies = movie.order('movies.release_date').all if params["sort"] == "release_date" end ... end
and here's index.html.haml
-# file app/views/movies/index.html.haml %h1 movies %table#movies %thead %tr %th{:class => @title_header} = link_to "movie title", {:sort => :title}, {:id => :title_header} %th rating %th{:class => @release_header} = link_to "release date", {:sort => :release_date}, {:id => :release_header} %th more info %tbody - @movies.each |movie| %tr %td= movie.title %td= movie.rating %td= movie.release_date %td= link_to "more #{movie.title}", movie_path(movie) = link_to 'add new movie', new_movie_path
also haven't started filter rating portion ignore in example.
edit: here's error mentioned in comments below
undefined method `order' #<array:0xae00ad8>
and here's of framework trace (no idea means... sorry wall of text)
actionpack (3.1.0) lib/action_controller/metal/implicit_render.rb:4:in `send_action' actionpack (3.1.0) lib/abstract_controller/base.rb:167:in `process_action' actionpack (3.1.0) lib/action_controller/metal/rendering.rb:10:in `process_action' actionpack (3.1.0) lib/abstract_controller/callbacks.rb:18:in `block in process_action' activesupport (3.1.0) lib/active_support/callbacks.rb:416:in `_run__379635507__process_action__868408152__callbacks' activesupport (3.1.0) lib/active_support/callbacks.rb:386:in `_run_process_action_callbacks' activesupport (3.1.0) lib/active_support/callbacks.rb:81:in `run_callbacks' actionpack (3.1.0) lib/abstract_controller/callbacks.rb:17:in `process_action' actionpack (3.1.0) lib/action_controller/metal/rescue.rb:17:in `process_action' actionpack (3.1.0) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action' activesupport (3.1.0) lib/active_support/notifications.rb:53:in `block in instrument' activesupport (3.1.0) lib/active_support/notifications/instrumenter.rb:21:in `instrument' activesupport (3.1.0) lib/active_support/notifications.rb:53:in `instrument' actionpack (3.1.0) lib/action_controller/metal/instrumentation.rb:29:in `process_action' actionpack (3.1.0) lib/action_controller/metal/params_wrapper.rb:201:in `process_action' activerecord (3.1.0) lib/active_record/railties/controller_runtime.rb:18:in `process_action' actionpack (3.1.0) lib/abstract_controller/base.rb:121:in `process' actionpack (3.1.0) lib/abstract_controller/rendering.rb:45:in `process' actionpack (3.1.0) lib/action_controller/metal.rb:193:in `dispatch' actionpack (3.1.0) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch' actionpack (3.1.0) lib/action_controller/metal.rb:236:in `block in action' actionpack (3.1.0) lib/action_dispatch/routing/route_set.rb:65:in `call' actionpack (3.1.0) lib/action_dispatch/routing/route_set.rb:65:in `dispatch' actionpack (3.1.0) lib/action_dispatch/routing/route_set.rb:29:in `call' rack-mount (0.8.3) lib/rack/mount/route_set.rb:152:in `block in call' rack-mount (0.8.3) lib/rack/mount/code_generation.rb:96:in `block in recognize' rack-mount (0.8.3) lib/rack/mount/code_generation.rb:75:in `optimized_each' rack-mount (0.8.3) lib/rack/mount/code_generation.rb:95:in `recognize' rack-mount (0.8.3) lib/rack/mount/route_set.rb:141:in `call' actionpack (3.1.0) lib/action_dispatch/routing/route_set.rb:531:in `call' actionpack (3.1.0) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call' rack (1.3.5) lib/rack/etag.rb:23:in `call' rack (1.3.5) lib/rack/conditionalget.rb:25:in `call' actionpack (3.1.0) lib/action_dispatch/middleware/head.rb:14:in `call' actionpack (3.1.0) lib/action_dispatch/middleware/params_parser.rb:21:in `call' actionpack (3.1.0) lib/action_dispatch/middleware/flash.rb:243:in `call' rack (1.3.5) lib/rack/session/abstract/id.rb:195:in `context' rack (1.3.5) lib/rack/session/abstract/id.rb:190:in `call' actionpack (3.1.0) lib/action_dispatch/middleware/cookies.rb:326:in `call' activerecord (3.1.0) lib/active_record/query_cache.rb:62:in `call' activerecord (3.1.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:477:in `call' actionpack (3.1.0) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call' activesupport (3.1.0) lib/active_support/callbacks.rb:392:in `_run_call_callbacks' activesupport (3.1.0) lib/active_support/callbacks.rb:81:in `run_callbacks' actionpack (3.1.0) lib/action_dispatch/middleware/callbacks.rb:28:in `call' actionpack (3.1.0) lib/action_dispatch/middleware/reloader.rb:68:in `call' rack (1.3.5) lib/rack/sendfile.rb:101:in `call' actionpack (3.1.0) lib/action_dispatch/middleware/remote_ip.rb:48:in `call' actionpack (3.1.0) lib/action_dispatch/middleware/show_exceptions.rb:47:in `call' railties (3.1.0) lib/rails/rack/logger.rb:13:in `call' rack (1.3.5) lib/rack/methodoverride.rb:24:in `call' rack (1.3.5) lib/rack/runtime.rb:17:in `call' activesupport (3.1.0) lib/active_support/cache/strategy/local_cache.rb:72:in `call' rack (1.3.5) lib/rack/lock.rb:15:in `call' actionpack (3.1.0) lib/action_dispatch/middleware/static.rb:53:in `call' railties (3.1.0) lib/rails/engine.rb:455:in `call' railties (3.1.0) lib/rails/rack/content_length.rb:16:in `call' railties (3.1.0) lib/rails/rack/log_tailer.rb:14:in `call' rack (1.3.5) lib/rack/handler/webrick.rb:59:in `service' /usr/local/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service' /usr/local/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run' /usr/local/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'
are using rails 4? should work
def index @movies = movie.all @movies.order!(:title) if params["sort"] == "title" @movies.order!(:release_date) if params["sort"] == "release_date" end
if using rails 3, modify controller instead:
def index @movies = movie.all @movies = @movies.order(:title) if params["sort"] == "title" @movies = @movies.order(:release_date) if params["sort"] == "release_date" end
what ever rails version, links should this:
= link_to "movie title", movies_path(:sort => 'title'), {:id => :title_header} ... = link_to "release date", movies_path(:sort => 'release_date'), {:id => :release_header}
Comments
Post a Comment