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