Rails 助手“集合选择”
我和 这个人 遇到了完全相同的问题,因为没有人回答,我决定重新发布:
我一直在尝试实现这个 jquery 插件到我的应用程序。我需要帮助 尝试输出类似的内容
<select name="user[university_id]" id="user_university_id" class="selectable">
<option value="1" title="uni1">Uni1</option>
<option value="2" title="uni2">Uni2</option>
</select>
通过使用 Rails 助手...问题 助手似乎从来没有输出过 选项标签的标题属性.. 这对于这个插件至关重要
请帮忙,提前致谢
编辑:我当前的 Rails 代码是
<%= f.collection_select(:university_id,University.all,:id,:name)%
它只是输出
<选择 name="user[university_id]" id="user_university_id"> <选项值=“1”>Uni1 <选项值=“2”>Uni2
所以基本上我需要的是一种方法 还将标题属性添加到我的 选项。
I have the exact same problem as this guy , since no one has answered, I decided to repost:
I have been trying to implement this
jquery plugin to my app.I need help
trying to output something like this
<select name="user[university_id]" id="user_university_id" class="selectable">
<option value="1" title="uni1">Uni1</option>
<option value="2" title="uni2">Uni2</option>
</select>
by using a rails helper...the problem
is the helpers never seem to output a
title attribute to the option tags..
which is critical for this pluginplease help, thanks in advance
Edit: my current rails code is
<%= f.collection_select(:university_id,University.all,:id,:name)%
which simply outputs
<select name="user[university_id]" id="user_university_id"> <option value="1">Uni1</option> <option value="2">Uni2</option> </select>
So basically what I need is a way to
also add title attribute to my
options.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它有点hacky,但你可以这样做:
这将用选项的文本内容分配标题。或者,您可以使用生成的 ID 执行更任意的操作。
Its a bit hacky but you could do something like:
This would assign the title with the text contents of the option. Alternatively you could do something more arbitrary using a generated ID.
你有没有想过推出自己的助手?我刚刚从 rails 源中复制了这段代码 然后更改名称并添加标题。
Have you thought about rolling your own helper? I just copied this code out of the rails source and then changed the name and added the title.