我有...simple_form爲什麼會生成一條不存在的路線?
/config/routes.rb:
Testivate::Application.routes.draw do
resources :areas do
resources :heuristics
end
end
/app/models/heuristic.rb:
class Heuristic < ActiveRecord::Base
attr_accessible :area_id
belongs_to :area
end
/應用/型號/area.rb:
class Area < ActiveRecord::Base
has_many :heuristics
end
/app/controllers/heuristics_controller.rb:
class HeuristicsController < ApplicationController
def new
@area = Area.find(params[:area_id])
@heuristic = @area.heuristics.build
respond_to do |format|
format.html # new.html.erb
format.json { render json: @heuristic }
end
end
end
/app/views/heuristics/new.html.haml:
%h1 New heuristic
= render 'form'
= link_to 'Back', area_heuristics_path(@area)
/應用/視圖/啓發式/_form.html.haml:
= simple_form_for @heuristic do |f|
= f.input :foo
= f.button :submit
我從來沒有明確地呼籲heuristics_path
,因爲這當然不存在。
爲什麼然後我在http://localhost:3000/areas/1/heuristics/new
得到以下錯誤?
NoMethodError in Heuristics#new
Showing /Users/steven/Dropbox/testivate/app/views/heuristics/_form.html.haml where line #1 raised:
undefined method `heuristics_path' for #<#<Class:0x007fea3b2ac1a0>:0x007fea3d027608>
Extracted source (around line #1):
1: = simple_form_for @heuristic do |f|
是的工作感謝和更乾淨。現在將閱讀邊緣指南。 –