ruby-on-rails/ redirect/ drop-down-menu
I used rails options_from_collection_for_select
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
I want <option value="215"><a href='http://www.google.com'>google</option>
and when I click a
I go to Google.
However, I just get <option value="215">Google</option>
.
If I use "<a href='http://www.google.com'>google</a>".to_s
, I get <option value="215"><a href='http://www.google.com'>google</a></option>
. Just a text, not a link.
What should I do ?
I think I know what you want to do and you have a flawed on what you want to do.
I think that you want to do is when someone selects something to go to a page
Expected output
<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();
});
Rails
<%=
select_tag "abc",
options_from_collection_for_select(@tenants, @tenant.url, @tenant.name", @tenant.id)
%>
I hope that this helps you out
Happy Hacking
<%= select_tag '<some_id>', options_from_collection_for_select(@tenants, :id, :tenant_text_value, current_tenant.try(:id)),:onchange => "window.location.href(this.value);" %>
or
<%= 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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.