select_tag 多个和部分
我遇到了一些讨厌的 select_tags 问题,我可以让它们在新标签上很好地显示数据,但在编辑时,它们不会显示,这是我目前拥有的代码。我想我需要使用 include?
但我不知道把它放在哪里。
这就是我目前所拥有的新内容
<% @data = Code.find(:all, :conditions => "section = 'Location'") %>
<%= select_tag "candidate[code_ids][]", options_for_select(@data.map{|d| ["#{d.value}",d.id]}), :multiple => true %>
,这是用于编辑的
<% @data = Code.find(:all, :conditions => "section = 'Location'") %>
<%= select_tag "candidate[code_ids][]", options_for_select(@data.map{|d| ["#{d.value}",d.id]},@found), :multiple => true %>
在我的控制器中,我有这个内容,它可以获取与该候选者相关的所有代码。
@results = Candidate.all :joins =>
"LEFT JOIN candidates_codes ON candidates.id = candidates_codes.candidate_id",
:conditions => ["candidates.id = ?", params[:id]],
:select => "candidates_codes.code_id"
#create an array of the candidates selected codes
@found = []
for c in @results
@found.push(c.code_id.to_i)
end
我怎样才能做到只有一项选择,而不是一项用于新建,一项用于编辑?
I'm having a problem with some pesky select_tags, I can get them to show data fine on the new but when it comes to edit, they don't show up, here is the code I have at the moment. I think I need to use include?
but I don't know where to put it.
This is what I have at the moment for the new
<% @data = Code.find(:all, :conditions => "section = 'Location'") %>
<%= select_tag "candidate[code_ids][]", options_for_select(@data.map{|d| ["#{d.value}",d.id]}), :multiple => true %>
And this is for the edit
<% @data = Code.find(:all, :conditions => "section = 'Location'") %>
<%= select_tag "candidate[code_ids][]", options_for_select(@data.map{|d| ["#{d.value}",d.id]},@found), :multiple => true %>
In my controller I have this which grabs all of the codes that are related to that candidate.
@results = Candidate.all :joins =>
"LEFT JOIN candidates_codes ON candidates.id = candidates_codes.candidate_id",
:conditions => ["candidates.id = ?", params[:id]],
:select => "candidates_codes.code_id"
#create an array of the candidates selected codes
@found = []
for c in @results
@found.push(c.code_id.to_i)
end
How can I make it so I only have one select rather than having one for new and one for edit?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在你问很久之后......但这就是我每次都能正确制作具有多选下拉重新加载的表单的方式。不可否认,这是使用参数而不是数据......
由于我使用的是 mongo_mapper,我可以像这样链接 Plucky 查询:
Long after you asked... But this is how I have been able to make a form with multi-select drop-down reload properly each time. Admittedly, this is using params and not data...
Since I am using mongo_mapper, I can just chain Plucky queries as so: