I have a little problem with my ruby/rails application.
I want to get the ID from my selected item and make a query with them.
In my _form I have:
<%= f.label "Stock", for: "text" %>
<%= f.select :stock_id, @stocks_list, {}, onchange: 'ShowUser(this.value)' %>
And my JavaScript code is:
function ShowUser(str){
alert("You select item with value: " + str);
}
I need catch 'str' value on my controller and show the information of the selected sotck dynamically (by a query).
update:
When I select a item just show the message in a pop-up and nothing else. My complete function is
function ShowUser(str)
{
alert("You select item with value: " + str);
JQuery.ajax( {
data: {valor: str},
type: 'post',
url: "/orders/create",
});
}
and the console log is
Started GET "/orders/new" for 127.0.0.1 at 2014-11-25 16:54:39 -0600
Processing by OrdersController#new as HTML
Staff Load (0.2ms) SELECT `staffs`.* FROM `staffs`
Provider Load (0.2ms) SELECT `providers`.* FROM `providers`
Stock Load (0.2ms) SELECT `stocks`.* FROM `stocks`
Rendered public/templates/menu.html.erb (1.0ms)
Rendered orders/_form.html.erb (6.8ms)
Rendered orders/new.html.erb within layouts/application (39.7ms)
Completed 200 OK in 273ms (Views: 268.3ms | ActiveRecord: 0.7ms)
when I select an item the console doesn't change