2016-05-22 12 views
1

私のアプリは、確かにネストされたルートをいくつか備えています。各トレーニングhas_many練習、および各運動has_many結果。新しいエクササイズを作成しようと、私はエラーを取得しています:ここでRails [POST] "/ exercises/new"に一致するルートはありません

<%= render 'exercises/form', exercise: Exercise.new, workout: @workout %> 

は部分的exercises/_form.html.erbです:ここで

No route matches [POST] "/exercises/new" 

は、すべての魔法が起きる私のworkouts#showページの一部であり、ここで

<%= form_for [workout, exercise] do |f| %> 

...(form stuff)... 

<div class="text-center"><%= f.submit "Create Exercise", class: 'btn btn-primary' %></div> 

<% end %> 

は私exercises#controllerです:

ここでは

そして、私のルートです:

workout_exercise_reports POST /workouts/:workout_id/exercises/:exercise_id/reports(.:format)  reports#create 
workout_exercise_report DELETE /workouts/:workout_id/exercises/:exercise_id/reports/:id(.:format) reports#destroy 
     workout_exercises GET /workouts/:workout_id/exercises(.:format)       exercises#index 
         POST /workouts/:workout_id/exercises(.:format)       exercises#create 
    new_workout_exercise GET /workouts/:workout_id/exercises/new(.:format)      exercises#new 
    edit_workout_exercise GET /workouts/:workout_id/exercises/:id/edit(.:format)     exercises#edit 
     workout_exercise GET /workouts/:workout_id/exercises/:id(.:format)      exercises#show 
         PATCH /workouts/:workout_id/exercises/:id(.:format)      exercises#update 
         PUT /workouts/:workout_id/exercises/:id(.:format)      exercises#update 
         DELETE /workouts/:workout_id/exercises/:id(.:format)      exercises#destroy 
       workouts GET /workouts(.:format)            workouts#index 
         POST /workouts(.:format)            workouts#create 
      new_workout GET /workouts/new(.:format)           workouts#new 
      edit_workout GET /workouts/:id/edit(.:format)          workouts#edit 
       workout GET /workouts/:id(.:format)           workouts#show 
         PATCH /workouts/:id(.:format)           workouts#update 
         PUT /workouts/:id(.:format)           workouts#update 
         DELETE /workouts/:id(.:format)           workouts#destroy 

これは、このroutes.rb構造から来ている:

resources :workouts do 
    resources :exercises do 
     resources :reports 
    end 
    end 

私は(エラーを修正する方法を含め、誰もが状況に当てることができるあらゆる知恵を歓迎します主に)私のルートを構成するためのより良い方法がある場合にも。

ADDITIONAL INFO

にここでは私のworkouts#controllerです:

class WorkoutsController < ApplicationController 
    def index 
    @workouts = Workout.all 
    end 

    def show 
    @workout = Workout.find(params[:id]) 
    workout = @workout 
    exercise = workout.exercises.new 
    end 

    def new 
    @workout = Workout.new 
    end 

    def create 
    @workout = Workout.new 
    @workout.name = params[:workout][:name] 
    @workout.workout_type = params[:workout][:workout_type] 
    @workout.teaser = params[:workout][:teaser] 
    @workout.description = params[:workout][:description] 
    @workout.video = params[:workout][:video] 
    @workout.difficulty = params[:workout][:difficulty] 
    @workout.trainer = params[:workout][:trainer] 
    @workout.user_id = params[:workout][:user_id] 

    if @workout.save 
     flash[:notice] = "Workout was saved successfully." 
     redirect_to @workout 
    else 
     flash.now[:alert] = "Error creating workout. Please try again." 
     render :new 
    end 
    end 

    def edit 
    @workout = Workout.find(params[:id]) 
    end 

    def update 
    @workout = Workout.find(params[:id]) 

    @workout.name = params[:workout][:name] 
    @workout.workout_type = params[:workout][:workout_type] 
    @workout.teaser = params[:workout][:teaser] 
    @workout.description = params[:workout][:description] 
    @workout.video = params[:workout][:video] 
    @workout.difficulty = params[:workout][:difficulty] 
    @workout.trainer = params[:workout][:trainer] 
    @workout.user_id = params[:workout][:user_id] 

    if @workout.save 
     flash[:notice] = "Workout was updated successfully." 
     redirect_to @workout 
    else 
     flash.now[:alert] = "Error saving workout. Please try again." 
     render :edit 
    end 
    end 

    def destroy 
    @workout = Workout.find(params[:id]) 

    if @workout.destroy 
     flash[:notice] = "\"#{@workout.name}\" was deleted successfully." 
     redirect_to action: :index 
    else 
     flash.now[:alert] = "There was an error deleting the workout." 
     render :show 
    end 
    end 
end 

そして、ここでは、エラーの完全なトレースです:

actionpack (4.2.5) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call' 
actionpack (4.2.5) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call' 
railties (4.2.5) lib/rails/rack/logger.rb:38:in `call_app' 
railties (4.2.5) lib/rails/rack/logger.rb:20:in `block in call' 
activesupport (4.2.5) lib/active_support/tagged_logging.rb:68:in `block in tagged' 
activesupport (4.2.5) lib/active_support/tagged_logging.rb:26:in `tagged' 
activesupport (4.2.5) lib/active_support/tagged_logging.rb:68:in `tagged' 
railties (4.2.5) lib/rails/rack/logger.rb:20:in `call' 
actionpack (4.2.5) lib/action_dispatch/middleware/request_id.rb:21:in `call' 
rack (1.6.4) lib/rack/methodoverride.rb:22:in `call' 
rack (1.6.4) lib/rack/runtime.rb:18:in `call' 
activesupport (4.2.5) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call' 
rack (1.6.4) lib/rack/lock.rb:17:in `call' 
actionpack (4.2.5) lib/action_dispatch/middleware/static.rb:116:in `call' 
rack (1.6.4) lib/rack/sendfile.rb:113:in `call' 
railties (4.2.5) lib/rails/engine.rb:518:in `call' 
railties (4.2.5) lib/rails/application.rb:165:in `call' 
rack (1.6.4) lib/rack/lock.rb:17:in `call' 
rack (1.6.4) lib/rack/content_length.rb:15:in `call' 
rack (1.6.4) lib/rack/handler/webrick.rb:88:in `service' 
/Users/elizabethbayardelle/.rbenv/versions/2.2.4/lib/ruby/2.2.0/webrick/httpserver.rb:138:in `service' 
/Users/elizabethbayardelle/.rbenv/versions/2.2.4/lib/ruby/2.2.0/webrick/httpserver.rb:94:in `run' 
/Users/elizabethbayardelle/.rbenv/versions/2.2.4/lib/ruby/2.2.0/webrick/server.rb:294:in `block in start_thread' 
+0

エラーを示す行は何行ですか? – uday

+0

いいえ、それは私のルートを表示するだけです... – Liz

+0

'[POST]"/exercises/new "'というルートはあなたのアプリケーションにありません。あなたのルートに '[GET]'があります。 –

答えて

1

あなたののトレーニングリソースの下にネスト演習を持っています。 したがって、新しいエクササイズを作成するには、エクササイズを作成しようとしているエクササイズを指定する必要があります。

ルートに示されているように、演習を作成するためのこのルートをヒットする必要があります。 [POST] /workouts/:workout_id/exercises/new エラー[POST] "/exercises/new"に表示されている内容の代わりに。

あなたのルートの設計には、あなたがどのエクササイズに属しているのかを指定する必要があります。そして、それぞれの報告書はどの運動とそれに属する運動を特定しなければならない。

要件が異なる場合は、デザインを変更することができます。

+0

入れ子を解除しようとしましたが、同じエラーメッセージが表示されます。 – Liz

+0

あなたはGETとして 'exercises/new'を定義しました –

関連する問題