Sorting data from database with Rails -
i suspect question stupid , answer obvious, totally stuck it.
in controller movies_controller.rb
have method index
, fills array @movies
values database calling @movies = movie.all
, , method sort
, same, use @movies = movie.order(:title)
instead.
if call sort
explicitly index
see in view index.html.haml
sorted title list of movies expect. but, how can call method sort
clicking on link? try
in index.html.haml:
%th= link_to 'movies title', 'movies', :on_click => 'self.sort'
in routes.rb:
match ":controller => movies, :action => sort" => 'movies/index'
and nothing happening, method sort
never executes. actually, have no idea how right. looks obvious everyone, me.
can find short answer how right? please, kick me in right direction!
if looking sorting data in table need plug in in place sort table according attribute. following jquery plugin that,
https://github.com/linjunpop/jquery-tablesorter-rails
or can achieve same background sorting order clause. check out following,
Comments
Post a Comment