rails:928
From: "y.igarashi" <y.igarashi@g...>
Date: Fri, 10 Feb 2006 15:33:30 -0800
Subject: [rails:928] パラメータの渡し方について
五十嵐と申します。
いろいろ調べたのですが解決しないので投稿しました。
ある顧客リストがあり住所と年収の独立したパラメータがあります。
そこから例えばTokyo、5000000と絞りこみ、両方に一致する顧客の
名前を列挙したいのですが、うまくいきません。
下に示したコードをご覧いただくとわかると思いますが、
5.のget_customer_nameのところでフィルタリングが年収のみで
おこなわれており、住所では行われていません。ここで住所のパラメータ
も引き渡したいのですが、その方法がわかりません。
もしくは下のコードとは関係なくobserve_fieldを用いて複数の
fieldを監視し、複数のパラメータを同時に一つの処理に返す方法が
あれば教えていただけると幸いです。
(コード中の数字は一応処理の順序を示しています。)
<<< controller >>>
3.
def get_customer_byaddress
@found_customer = Customer.find_by_sql("SELECT * from customers
where address = "@params[:address]"") )
render(:partial => "list_customer_byaddress")
end
5.
def get_customer_name
@found_customer = Customer.find_by_sql("SELECT * from customers
where income = "@params[:income]") )
render(:partial => "list_customer_byincomeandaddress")
end
<<< view >>>
1. <div id="customer_address"><%= text_field :customer, :address %></div>
4. <div id="customer_income"></div>
6. <div id="customer_list"></div>
2.
<%= observe_field("customer_address",
:frequency => 0.5,
:complete => "eval(request.resonseText)",
:update => "customer_income",
:url => {:action => get_customer_byaddress},
:with => "'address='+escape(value)"
)}%>
4.
<<_list_customer_byaddress.rhtml>>
<%= select :customer, :income, @found_customer.collect{|i|i.income},
{'OnChange' => remote_function(:update => "customer_list",
:url => {:action => get_customer_name},
:with => "'income='+escape(value)"
)}%>
6.
<<_list_customer_byincomeandaddress.rhtml>>
<%= select :customer, :name, @found_customer.collect{|i|i.name}%>
--
ML: rails@r...
使い方: http://QuickML.com/
-> 928 2006-02-11 00:33 [y.igarashi@g... ] パラメータの渡し方について 929 2006-02-11 05:09 ┗[shachi@j... ] 932 2006-02-12 00:53 ┗[y.igarashi@g... ]