2016-07-06 12 views
0

検証エラーが更新されるとルーティングの問題が発生します。
私は検証エラーを修正するときレールでのルーティングエラー4

Started POST **"/employees"** for 127.0.0.1 at 2016-07-06 14:07:23 +0530 Processing by EmployeesController#create as HTML 

がどのように私は、/ new.Thisが発生したルートの従業員を取得することができ、私は

Started POST **"/employees/new"** for 127.0.0.1 at 2016-07-06 14:07:23 +0530 Processing by EmployeesController#create as HTML 

をしたいが、私は得ます。これが解決した場合は

resources :employees 
get 'new' => 'employee#new' 
get 'create' => 'employee#create' 
get 'index' => 'employee#index' 

と_controller /メソッドを作成し、

if @employee.save 
    respond_to do |format| 
     format.html {redirect_to action: "index"} 
    end 
    else 
    render 'new' 
    end 

、データは保存しないが、それはROLLBACKになります。

+0

については

resources :employees, only: [:show, :edit, :update, :index]

、私はコードで私の質問を更新 –

+0

_controller.rb' '私にあなたの' routes.rb'とあなたのファイルを表示してください。 – Prabha

+1

あなたが得ている投稿は正しいです。保存できない場合は 'new'をレンダリングしますが、あらかじめそのポストを保持します。詳細については、リクエスト+レスポンスのログエントリ全体を投稿してください。 – Matt

答えて

0

多分あなたのようなルートで複数化を試みてください。コントローラ

def create @employee = Employee.create if @employee.valid? redirect_to root_path else render :new, :status => :unprocessable_entity end end

+0

Ya ,.それは仕事かもしれない。私はこのようにしてみます。お返事をありがとうございます。 – Prabha

関連する問題