rails:208
From: yu1@t...
Date: Thu, 16 Jun 2005 20:39:00 +0900
Subject: [rails:208] Re: 複数のsubmitボタン
g0rOuです。
こんなんでどうでしょうか。
render :うんちゃら なメソッドはrailsのsvn headじゃないと
動かないと思います。
0.12.1の場合適当な修正が必要です。
- application.rb
class ApplicationController < ActionController::Base
def action_routing(accept_action_routing = [],prefix = 'action',sep = '=')
route_regex = Regexp.new "^#{prefix}#{sep}(.+)$"
@params.each do |key,value|
if m = route_regex.match(key)
return redirect_to :action => m[1] if accept_action_routing.include?(m[1])
end
end
#とばすアクションが見つからなかった。ここまで来たらエラー
raise ::ActionController::UnknownAction, "No action (action_routing) to #{action_name}"
end
end
-test_controller.rb
class TestController < ApplicationController
def index
render :inline => %q|
<html>
<body>
<%= form_tag :action => :submit %>
<%# 通常は必要なフォーム要素いろいろ書く %>
<%= submit_tag "削除", { :name => 'action=delete' } %>
<%= submit_tag "更新", { :name => 'action=edit' } %>
<%# その他はエラー %>
<%= submit_tag "その他", { :name => 'action=other' } %>
<%= end_form_tag %>
</body>
</html>
|
end
def submit
action_routing(['delete','edit'])
end
def delete
render :text => '削除です'
end
def edit
render :text => '編集です'
end
def other
render :text => 'ここにはリダイレクトされてくることはありません'
end
end
---------------------
うーん、これだと結構冗長な気がします、、、。
filterに引数渡せればfilterに登録できてもっとスマートになりそうなんですが、
うまい方法を知ってる方はご教示ください。
---------------------------------------
http://rails2u.com
gorou <hotchpotch@g...>
--
ML: rails@r...
使い方: http://QuickML.com/
207 2005-06-16 09:51 [abe@c... ] 複数のsubmitボタン -> 208 2005-06-16 13:39 ┗[yu1@t... ] 209 2005-06-16 22:31 ┗[abe@c... ]