Rails:使用observe_field返回空白选择选项?
我的应用程序中有一个observe_field调用,如下所示:
= observe_field "marketSelect", :update => "merchantSelect", :with => "id", :url => { :controller => "markets", :action => "get_merchants" }
该代码在我的市场控制器中激活以下操作:
@merchants = @market.merchants.sort_by { |merchants| merchants.name }
该代码返回与所选市场关联的每个商家的列表,并将它们填充到另一个选择列表中。
如何与商家一起插入空的“选择商家...”?
谢谢
I have an observe_field call in my app like this:
= observe_field "marketSelect", :update => "merchantSelect", :with => "id", :url => { :controller => "markets", :action => "get_merchants" }
That code activates the following action in my markets controller:
@merchants = @market.merchants.sort_by { |merchants| merchants.name }
That code returns a list of every merchant associated with the selected market, and populates them into another selection list.
How can I insert an empty "Select merchant..." along with the merchants?
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
嗯..我在 http://joshhuckabee.com/rails-observe-field 找到了这个-function-and
作者用prototype做到了这一点。他添加了一个小片段,用 HTML 换行符替换回车符,并且在未输入文本或字段被清除时设置默认值。
Hmm.. I found this at http://joshhuckabee.com/rails-observe-field-function-and
The author did this with prototype. He had added a little snippet that will replace carriage returns with HTML line breaks and also set a default value if no text is entered or the field gets cleared out.
谢谢你的建议。我最终只是构建了一个直接的 javascript 解决方案。
Thanks for the suggestion. I ended up just building a straight javascript solution.