Rails - Drop down menu to execute actions in the controller?

若如初见. 提交于 2019-12-04 20:19:57

If you don't mind using jQuery, this is what I would do:
Have a hash defined something like:

@urls = {"Create New USer..." => new_user_url, "Create new expense", => new_expense_path}

Then in the view have:

select_tag :create-model, options_for_select(@urls)

Then in application.js or something like that

$('#create-model').change(function() {
  window.location = $(this).find('option:selected').val();
});

I haven't tried it but it should work without too much editing.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!