我想创建一个表单,用户可以键入他们的电子邮件,它会将其保存到数据库。我希望这个表格在每一页的页脚中。Rails为什么我得到未定义的方法
我已经通过铁轨脚手架生成了NewsletterSignup。
现在我有这样的代码在我/app/views/refinery/_footer.html.erb:
<%= form_for(@newsletter_signup) do |f| %>
<div class="field">
<%= f.label :email %><br />
<%= f.text_field :email %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
,当我尝试并加载网页我得到这个错误:
NoMethodError in Refinery/pages#home
Showing /Users/tomcaflisch/Sites/PersonalTrainingKT/app/views/refinery/_form.html.erb where line #1 raised:
undefined method `newsletter_signups_path' for #<#<Class:0x007fb84c769ba0>:0x007fb84c08d110>
为什么该方法未定义?如果我运行耙路线我可以看到它的存在:
newsletter_signups GET /newsletter_signups(.:format) newsletter_signups#index
POST /newsletter_signups(.:format) newsletter_signups#create
new_newsletter_signup GET /newsletter_signups/new(.:format) newsletter_signups#new
edit_newsletter_signup GET /newsletter_signups/:id/edit(.:format) newsletter_signups#edit
newsletter_signup GET /newsletter_signups/:id(.:format) newsletter_signups#show
PUT /newsletter_signups/:id(.:format) newsletter_signups#update
DELETE /newsletter_signups/:id(.:format) newsletter_signups#destroy
的routes.rb
PersonalTrainingKT::Application.routes.draw do
resources :newsletter_signups
# This line mounts Refinery's routes at the root of your application.
# This means, any requests to the root URL of your application will go to Refinery::PagesController#home.
# If you would like to change where this extension is mounted, simply change the :at option to something different.
#
# We ask that you don't use the :as option here, as Refinery relies on it being the default of "refinery"
mount Refinery::Core::Engine, :at => '/'
end
我也创建在application_controller一个新的对象,因为这简报注册将可在每一页上:
class ApplicationController < ActionController::Base
protect_from_forgery
before_filter :instantiate_newsletter_signup
def instantiate_newsletter_signup
@newsletter_signup = NewsletterSignup.new
end
end
可以看到你们的路线文件? – ctcherry 2012-07-26 03:01:03
我已经张贴了我的路线,除了炼油厂的路线 - 其中有一大堆那些。 – Catfish 2012-07-26 03:03:08
我认为我所需要做的就是将form_for专门用于我的newsletter_signups_controller对吗? – Catfish 2012-07-26 03:03:58