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.

Related Question Rails show index results from options_from_collection_for_select Tooltip for options_from_collection_for_select on Rails Rails - How do display an integer in options_from_collection_for_select? How to add data attribute for options_from_collection_for_select in rails Rails select_tag css with options_from_collection_for_select Rails options_from_collection_for_select return unique year values rails options_from_collection_for_select ajax request ActionView: options_from_collection_for_select in rails view Inner Join in Rails options_from_collection_for_select How can edit and manage “select_tag options_from_collection_for_select” in Ruby on Rails application?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM