に移動するnew_heuristic_variant_cycle_path
と、アプリにサイクルの新しいビューが表示されますが、フォームの送信ボタンに「サイクルの作成」ではなく「サイクルの更新」と表示され、送信ボタンをクリックすると、コントローラーが更新アクションを探します。なんで?
私は持っています...
/config/routes.rb:
Testivate::Application.routes.draw do
resources :heuristics do
resources :variants do
resources :cycles
end
end
end
/app/models/heuristics.rb:
class Heuristic < ActiveRecord::Base
has_many :variants
has_many :cycles, :through => :variants
end
/app/models/variants.rb:
class Variant < ActiveRecord::Base
belongs_to :heuristic
has_many :cycles
end
/app/models/cycles.rb:
class Cycle < ActiveRecord::Base
belongs_to :variant
end
/app/views/cycles/new.html.haml:
%h1 New Cycle
= render 'form'
/app/views/cycles/_form.html.haml:
= simple_form_for [@heuristic, @variant, @cycle] do |f|
= f.button :submit
/app/controllers/cycles_controller.rb:
class CyclesController < ApplicationController
def new
@heuristic = Heuristic.find(params[:heuristic_id])
@variant = @heuristic.variants.find(params[:variant_id])
@cycle = @variant.cycles.create
respond_to do |format|
format.html # new.html.erb
end
end
def create
@heuristic = Heuristic.find(params[:heuristic_id])
@variant = @heuristic.variants.find(params[:variant_id])
@cycle = @variant.cycles.create(params[:cycle])
respond_to do |format|
if @cycle.save
format.html { redirect_to heuristic_variant_cycles_path(@heuristic, @variant, @cycle), notice: 'Cycle was successfully created.' }
else
format.html { render action: "new" }
end
end
end
end