gpt4 book ai didi

ruby-on-rails - 在 Rails 中将 Action 关联到 form.select 的 on_change?

转载 作者:数据小太阳 更新时间:2023-10-29 08:29:33 26 4
gpt4 key购买 nike

以下是我选择聊天室的下拉列表:

<% form_for :chat_room do |form| %>
<%= form.select(:title, @chat_rooms.collect! {|x| x.title},{:include_blank =>'select a chat room'}) %>
<% end %>

我的路线是:

ActionController::Routing::Routes.draw do |map|

map.resource :account, :controller => "users"
map.resources :poll
map.resources :users,:has_many => :stories
map.resources :chat_rooms ,:member => {:create_message => :post},:collection => {:ajax_updater=>:get}
map.logout 'logout', :controller => 'user_sessions', :action =>'destroy'
map.resource :user_session
map.resource :welcome
map.connect '/', :controller => 'welcome', :action => 'index'

map.connect ':controller/:action/:id'
map.connect ':controller/:action/:id.:format'
end

在更改下拉列表中的值时,我想导航到所选的特定聊天室。我该怎么做?

最佳答案

一种(简单的)方法是将 :onchange 参数添加到选择助手

form.select(:title, @chat_rooms.collect! {|x| [x.title, x.id] },{:include_blank =>'select a chat room'}, :onchange => 'window.location.href = "chat_rooms/" + this.getAttribute("value")')

关于ruby-on-rails - 在 Rails 中将 Action 关联到 form.select 的 on_change?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/720895/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com