![](/img/trans.png)
[英]Rails show index results from options_from_collection_for_select
[英]How to show html in rails options_from_collection_for_select
我使用rails options_from_collection_for_select
進行選擇。
options_from_collection_for_select(@tenants, :id, :tenant_text_value, current_tenant.try(:id))
def tenant_text_value
"<a href='http://www.google.com'>google</a>".html_safe
end
我需要<option value="215"><a href='http://www.google.com'>google</option>
,當我單擊a
我轉到Google。
但是,我只是得到<option value="215">Google</option>
。
如果我使用"<a href='http://www.google.com'>google</a>".to_s
, "<a href='http://www.google.com'>google</a>".to_s
得到<option value="215"><a href='http://www.google.com'>google</a></option>
。 只是文本,而不是鏈接。
我該怎么辦 ?
我想我知道您想做什么,而您想做什么卻有缺陷。
我認為您要做的是當某人選擇要轉到頁面的內容時
預期產量
<select id="abc">
<option value="http://www.google.com">Google</option>
<option value="http://www.yahoo.com">Yahoo</option>
<option value="http://www.google.com">Bing</option>
</select>
$("#abc").change(function() {
window.location.href = $(this).val();
});
滑軌
<%=
select_tag "abc",
options_from_collection_for_select(@tenants, @tenant.url, @tenant.name", @tenant.id)
%>
我希望這可以幫助您
快樂黑客
<%= select_tag '<some_id>', options_from_collection_for_select(@tenants, :id, :tenant_text_value, current_tenant.try(:id)),:onchange => "window.location.href(this.value);" %>
要么
<%= select_tag '<some_id>', options_from_collection_for_select(@tenants, :id, :tenant_text_value, current_tenant.try(:id)) %>
<script>
$(function(){
$('#team_id').bind('change', function () {
var url = $(this).val()
if (url) {
window.location.href(url);
}
return false;
});
});
</script>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.