Avi
(Avi)
December 20, 2012, 4:53am
1
Hello,
I have a dropdown in the UI. There are many oprions.
How do I send the parameter from the dropdown - the selected value to the controller?
I have tried :-
<%= select_tag ‘name’, options_for_select(@list , :selected) %>
<%= select(“audit”, “value”,options_for_select([[“User Registration”, “USER_REGISTRATION”], [“Download”, “USER_REPORT”]], :selected => params[:value]) %>
I am not getting any parameters passed to the controller.
Hello,
I have a dropdown in the UI. There are many oprions.
How do I send the parameter from the dropdown - the selected value to the
controller?
I have tried :-
1. <%= select_tag 'name', options_for_select(@list , :selected) %>
2. <%= select("audit", "value",options_for_select([["User Registration",
"USER_REGISTRATION"], ["Download", "USER_REPORT"]], :selected =>
params[:value]) %>
I am not getting any parameters passed to the controller.
make sure that the select tag above is part of the form you are submitting
and that you
are actually submitting to the right action. A quick look on your code
raised no issues.
Avi
(Avi)
December 20, 2012, 5:45am
3
I am not adding any form because there is no model for this page.
Only there is controller and view.
I am not adding any form because there is no model for this page.
Only there is controller and view.
you need to add a form to pass the selected values to the controller. It
doesn't
matter whether you're accessing a model or not.
Avi
(Avi)
December 21, 2012, 6:46am
5
Sorry for late reply…
Can’t we pass the param through ajax or js ?
Sorry for late reply...
Can't we pass the param through ajax or js ?
yes you can. you have to read on ajax.
Avi
(Avi)
December 21, 2012, 12:32pm
7
Somehow I did manage to pass the parameter from the dropdown to controller.
But the problem is here - I am getting it as string.
In Controller:----
class ReportController < ApplicationController
REPORT1 = “type =?”, “Box”
REPORT2 = “action = ? and type =?”, “create”, “Square”
def report
param = params[:audit_report] // How to convert this string to an object or static variable ? Or what is the best way to do it ?
@report_data = (Audited::Adapters::ActiveRecord::Audit.where(param))
// If I am passing this param, it comes as a string not as static varaible in this controller.
end
end
In View :----
<%= select_tag “reports_name”, options_for_select([[“User1”, “REPORT1”], [“User2”, “REPORT2”]]), :onchange =>“audit_options(this.value)” %>
Somehow I did manage to pass the parameter from the dropdown to controller.
But the problem is here - I am getting it as string.
In Controller:----
class ReportController < ApplicationController
REPORT1 = “type =?”, “Box”
REPORT2 = “action = ? and type =?”, “create”, “Square”
def report
param = params[:audit_report] // How to convert this string to an object or static variable ? Or what is the best way to do it ?
@report_data = (Audited::Adapters::ActiveRecord::Audit.where(param))
// If I am passing this param, it comes as a string not as static varaible in this controller.
end
end
In View :----
<%= select_tag “reports_name”, options_for_select([[“User1”, “REPORT1”], [“User2”, “REPORT2”]]), :onchange =>“audit_options(this.value)” %>
You should read on action controller basics. And also on debugging using pry or debugger so you can experiment on what you want to achieve. Good luck!