0
我遇到了PATCH请求的问题。Rails使用PATCH请求渲染或redirect_to
我想PATCH "/activities/7/mans"
和update
一些价值
但如果更新值无效,那么我怎么会重定向到:new
?
这里的铁轨服务器日志
Started PATCH "/activities/7/mans" for 127.0.0.1 at 2015-05-04 12:55:58 +0800
Processing by MansController#new as HTML
Parameters: {"utf8"=>"✓","authenticity_token"=>"Qnn/N9yWMtxAwA9N+br5r+mMvPdoY4fBJaI3sCYnObY=","activity_id"=>"7"}
当我使用更新
我总是得到{GET} not {PATCH}
Started GET "/activities/7/mans" for 127.0.0.1 at 2015-05-04 12:58:56 +0800
Processing by MansController#show as HTML
Parameters: {"activity_id"=>"7"}
这里后呈现新的route.rb设置
resources :activities do
resources :mans, :only => [:index ,:create] do
collection do
patch :new
end
end
end
这里是我的控制器操作
def new
@activity = Activity.find_by_id(params[:activity_id])
@man= Man.new
end
def create
@man = Man.new(man_params)
if @man.age <20
redirect_to :new
end
end
你能告诉你的控制器行动?这很可能与您如何进行重定向有关。 – jphager2