ruby on rails - How to use a select to go to the Show action of another controller? -


I am trying to do something that I thought was simple and natural but I am struggling. .

On the homepage of my website, I want to make a selection containing a list of users. After selecting the user and after clicking on a button, the user should go to the show action of the controller page.

I searched and found various searches that I am not very elegant:

<
  • Use of AJX
  • Modifying the URL in the HTML Using an Inspection_film for

Is there a better way of doing this?

What will be the best way?

I would probably do it with jQuery ... or just plain old Javascript Click

  $ ("# button_id") (function () {window.location = '/ users /' + $ ("# select_list_id"). Children ("Options: Selected") .val ();});  

An onclick method should be added to that button and then you should send it to '/ user / 12345'.

You can do the same in plain JavaScript if you are not using Jquery, but it involves a bit more.

  & lt; Script type = "javascript" & gt; Function goToUsersPage () {list = document.getElementById ('select_list_id') window.location = '/ users' + list.options [selectedIndex] .value; } & Lt; / Script & gt;  

Then you have to add the function call to the onclick method of your button.

  & lt; Input type = 'button' onclick = 'goToUsersPage (); ''! Go 'value = />  

Comments

Popular posts from this blog

MySql variables and php -

c# - How can I find out if there are windows above a control? -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -