I am using a select menu to allow people to pick an item and be taken to
a new page containing that item''s data. Pretty straightforward stuff.
Except that I cannot quite figure out how to do this in Rails.
I do not understand how to grab the variable from the select menu. With
the code I am using, I cannot get the data into the mysql query.
Can someone point me in the right direction?
This is the code for the select menu (it uses an array of arrays in the
model file):
<%= start_form_tag :action => ''history'' %>
<table width="450">
<tr>
<td align="right"><%= options = [["Select
client", ""]] +
Notification::CLIENTS
select("notification", "client", options) %></td>
<td align="left"><%= submit_tag "Select"
%></td>
</tr>
</table>
<%= end_form_tag %>
This is the code in the controller:
def history
if(params[:notification])
@client = (params[:notification])
@notifications = Notification.find(:all, :conditions => ["client
?", @client])
end
end
Thanks!
Nathan Mealey
Operations Director
Northeast Region
Pilgrim IT, LLC
NORTHEAST OFFICE
1 Short Street
Northampton, MA 01060
TEL 866.434.4976
FAX 413.587.0572
MIDWEST OFFICE
1815 Brownsboro Road
Louisville, KY 40206
TEL 502.721.7939
FAX 502.721.7940
NOTICE: This email and any attachments are intended only for the
addressee and may contain information that is confidential and/or
legally privileged. If you are not the intended recipient or have
received this email in error, please notify the sender by return email
or by calling 866-434-4976. You should then delete the message and any
attachments or copies. If you are not the intended recipient, you are
prohibited from retaining, distributing, disclosing or using any
information contained herein.
_______________________________________________
Rails mailing list
Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails
This is the code straight from my app.
function initSelect(){
var theSelect = document.getElementById("event_state_id");
theSelect.changed = false;
theSelect.onchange = selectChanged;
return true;
}
function selectChanged(theElement){
var theSelect;
if (theElement && theElement.value) {
theSelect = theElement;
}else{
theSelect = this;
}
try {xhr = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {
try {xhr = new ActiveXObject("Microsoft.XMLHTTP");} catch (E) {xhr
false;}}
if (!xhr && typeof XMLHttpRequest != ''undefined'') {xhr
= new
XMLHttpRequest();}
xhr.open("GET", "url/"+theSelect.value);
xhr.onreadystatechange=function() {
if (xhr.readyState != 4) return;
target = document.getElementById("event_city_custom");
target.innerHTML = xhr.responseText;
}
xhr.send(null);
return true;
}
<tr>
<td>
<label for="event_state">State:</label>
</td>
<td>
<%= select( "event",
"state_id",
State.all_with_please_select_option) %> <br />
</td>
</tr>
HTH.
-=- Neeraj
www.neeraj.name <http://www.neeraj.name>
On 11/8/05, Nathan Mealey
<nmealey-Tgd3YNkSzkDby3iVrkZq2A@public.gmane.org>
wrote:>
> I am using a select menu to allow people to pick an item and be taken to
> a new page containing that item''s data. Pretty straightforward
stuff. Except
> that I cannot quite figure out how to do this in Rails.
>
> I do not understand how to grab the variable from the select menu. With
> the code I am using, I cannot get the data into the mysql query.
>
> Can someone point me in the right direction?
>
> This is the code for the select menu (it uses an array of arrays in the
> model file):
>
> <%= start_form_tag :action => ''history'' %>
>
> <table width="450">
>
> <tr>
>
> <td align="right"><%= options = [["Select
client", ""]] +
> Notification::CLIENTS
>
> select("notification", "client", options)
%></td>
>
> <td align="left"><%= submit_tag "Select"
%></td>
>
> </tr>
>
> </table>
>
> <%= end_form_tag %>
>
> This is the code in the controller:
>
> def history
>
> if(params[:notification])
>
> @client = (params[:notification])
>
> @notifications = Notification.find(:all, :conditions => ["client =
?",
> @client])
>
> end
>
> end
>
> Thanks!
>
> *Nathan Mealey***
>
> Operations Director
>
> Northeast Region
>
> *Pilgrim IT, LLC*
>
> * *
>
> *NORTHEAST OFFICE*
>
> 1 Short Street
>
> Northampton, MA 01060
>
> TEL 866.434.4976
>
> FAX 413.587.0572
>
> *MIDWEST** OFFICE*
>
> 1815 Brownsboro Road
>
> Louisville, KY 40206
>
> TEL 502.721.7939
>
> FAX 502.721.7940
>
> NOTICE: This email and any attachments are intended only for the
> addressee and may contain information that is confidential and/or legally
> privileged. If you are not the intended recipient or have received this
> email in error, please notify the sender by return email or by calling
> 866-434-4976. You should then delete the message and any attachments or
> copies. If you are not the intended recipient, you are prohibited from
> retaining, distributing, disclosing or using any information contained
> herein.
>
>
> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
>
>
_______________________________________________
Rails mailing list
Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails
Nathan, I''m a noob, but I think you need to change @client = (params[:notification]) to @client = @params[''notification''][''client''] The parameter is in a multi-dimension hash. I hope this helps, Brent Middaugh On 11/8/05, Nathan Mealey <nmealey-Tgd3YNkSzkDby3iVrkZq2A@public.gmane.org> wrote:> > > > I am using a select menu to allow people to pick an item and be taken to a > new page containing that item''s data. Pretty straightforward stuff. Except > that I cannot quite figure out how to do this in Rails. > > I do not understand how to grab the variable from the select menu. With the > code I am using, I cannot get the data into the mysql query. > > > > Can someone point me in the right direction? > > > > This is the code for the select menu (it uses an array of arrays in the > model file): > > <%= start_form_tag :action => ''history'' %> > > <table width="450"> > > <tr> > > <td align="right"><%= options = [["Select client", ""]] + > Notification::CLIENTS > > select("notification", "client", options) %></td> > > <td align="left"><%= submit_tag "Select" %></td> > > </tr> > > </table> > > <%= end_form_tag %> > > > > This is the code in the controller: > > def history > > if(params[:notification]) > > @client = (params[:notification]) > > @notifications = Notification.find(:all, :conditions => ["client = ?", > @client]) > > end > > end > > > > Thanks! > > > > Nathan Mealey > > Operations Director > > Northeast Region > > Pilgrim IT, LLC > > > > NORTHEAST OFFICE > > 1 Short Street > > Northampton, MA 01060 > > TEL 866.434.4976 > > FAX 413.587.0572 > > > > MIDWEST OFFICE > > 1815 Brownsboro Road > > Louisville, KY 40206 > > TEL 502.721.7939 > > FAX 502.721.7940 > > > > NOTICE: This email and any attachments are intended only for the addressee > and may contain information that is confidential and/or legally privileged. > If you are not the intended recipient or have received this email in error, > please notify the sender by return email or by calling 866-434-4976. You > should then delete the message and any attachments or copies. If you are not > the intended recipient, you are prohibited from retaining, distributing, > disclosing or using any information contained herein. > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >