Sorting alphabetically in ruby on rails -


how make activerecord sort movies title alphabetically when click on link in ruby on rails? movies contains title alphabets , others numbers. thanks

without knowing details of application, following migration file:

class createmovies < activerecord::migration   def change     create_table :movies |t|       t.string :title       t.text :description        t.timestamps     end   end end 

and model:

class movie < activerecord::base end 

and controller:

class moviescontroller < applicationcontroller   def index     @movies = if params[:sort_by] == "title"        movie.order(:title)     else       movie.all     end   end end 

and in view:

<%= link_to "all movies", movies_path %> <%= link_to "movies sorted alphabetially", movies_path(sort_by: "title") %> 

Comments