Jump to content

The ultimate community for Ruby on Rails developers.


Pass params from select list by push a button to the controller for sort choose

params select sort button

  • Please log in to reply
No replies to this topic

#1 jerome___



  • Members
  • 6 posts

Posted 16 November 2013 - 10:38 AM

Attached File  movies_controller.txt   4.39KB   291 downloadsHello,


I'm a newbie on Rails (use version 4.0.1) and i would like to know and understand how to pass some params who has been selected from selected lists box (in the html view) via a push button to the controller of the same page view.

The interest of doing that (i hope without javascript or jquery) is to make a selection of "sort-by" inside a select list (for example, i have some movies, and each of them have a title, a notation, a style, a date of release, etc.. inside a database table; and so, i would like to indicate truth this select box which column of this database i need to sort for the view list). And also, some other select list for eventually choose which one to view or not.

Like that, i could view on a list, for example, all movies, with "style=Action-movies AND date between 1990 & 2000", "sort by TITLE".


from now, i'm able to

_ create a movie with all params i need (and select list with enum fonction from MySQL...)

_ update and show one of them

_ view a list sort by titles (and integrate with the perfect paginate gem... very nice !)

_ see my selected boxes for sort and selection

but can not be able to make the link between this selection options and my list of movies...



i make follow two files: my movies_controller and my index view (sure that can be more clear for the problem)

Attached File  movies_controller.txt   4.39KB   291 downloads


but here is an example of my method inside movies_controller:


 def show_sort
    raise CanCan::AccessDenied unless can?(:read,Movie)
    puts "=dddddddd"
    @movies = Movie.order(:choose).page(params[:page]).per(6)
    render 'index'

and here is the part of routes file linked to the method/action call


resources :movies do
    get 'show_sort', on: :member


(impossible to upload the view file... so i need write here a part of it for example show)


<section id='list_movie'>
<%= paginate @movies %><div id="info_movies"> <%= page_entries_info @movies %></div>
<div class="choose"><table>
 <col style="width:10%">
 <col style="width:20%">
 <col style="width:40%">
 <col style="width:10%">
 <col style="width:20%">
<td>Sort by : </td>
<td> <%= select(:choose, ["",:title, :date, :note], ["","title", "date of parution", "note"] ) %></td>
<td> </td>
<td>Only for : </td>
<td><%= select(:style_select, @movies.find(id="1").enum_all(:style), @movies.find(id="1").enum_all(:style) ) %></td>
<td>From : </td>
<td><%= select(:date_from_select, 1950..Time.now.year, 1950..Time.now.year ) %></td>
<td colspan="2"> </td>
<td><%= select(:note_select, @movies.find(id="1").enum_all(:note), @movies.find(id="1").enum_all(:note) ) %></td>
<td>To : </td>
<td><%= select(:date_to_select, 1950..Time.now.year, 1950..Time.now.year ) %></td>
<td colspan="3"> </td>

<%= button_to "Sort now", show_sort_movie_path(@movies), :method => 'get'  %></div>


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users