Rails select_tag onchange 操作没有 Ajax?
在时间控制器的索引操作中,我希望能够在显示的时间之间切换。 我正在使用 calendar_for 表,并在日历内显示 Rails 应用程序的不同用户的跟踪时间(小时)。 由于我使用的日历结构相当复杂,内部有一些计算,所以我不知道如何将其提取到部分,因此我希望在 select_tag 中触发的 onchange 事件使用不同的参数重新加载索引操作。
我尝试过
<% form_for :hours, :url => { :action => "index" } do |f| %>
<%= select_tag :user_id, options_from_collection_for_select(User.find(:all), :id, :name),
{ :onchange => "this.form.submit();"} %>
<% end %>
,但这将我带到新的/表单视图(就像我想添加新记录)?另外,网址仅显示 /hours
任何帮助将不胜感激......
我基本上希望在更改选择菜单后,网址看起来像 /hours?user_id=
In my index action of the hours controller I want to be able to switch between the diplayed hours.
I am using a calendar_for table and inside the calendar I display the tracked times (hours) of the different user of my rails app.
As I am using a quite complex calendar structure with some calculation inside, I don't know how to extract it to a partial, so I want the onchange event, which fires in the select_tag, to reload the index action with a different parameter.
I tried
<% form_for :hours, :url => { :action => "index" } do |f| %>
<%= select_tag :user_id, options_from_collection_for_select(User.find(:all), :id, :name),
{ :onchange => "this.form.submit();"} %>
<% end %>
but this brings me to the new / form view (like i want to add a new record)? also the url just shows /hours
Any help would be appreciated....
I basically want that after changing the select menu the url looks like /hours?user_id=<id from select_tag>
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不太明白为什么需要表格?我认为最简单的方法是使用类似的内容更新您的
application.js
文件(假设您使用 jquery):尽管可能有一些漂亮的 Rails 帮助程序。
I do not quite understand why do you need a form? The simplest way from my opinion is update your
application.js
file with something like this (assuming you use jquery):Though probably there is some pretty rails helper for that.