Newsletter signup form in the main layout
class NewslettersController < ApplicationController
def signup
@signup=Newsletter.new(params[:newsletter])
@signup.save
end
end
I want call this to the layouts/application.html.erb.
I created a partial newsletters/_signup: <%= form_for @newsletter, :html => {:multipart => true} do |f| -%>
<div class="field">
<%= f.label :email %><br />
<%= f.text_field :email %>
</div>
<%= f.submit 'Go!' %>
<% end -%>
But when I use render :partial => "newsletters/signup" I got undefined method `model_name' for NilClass:Class.
Whats wrong? (Rails 3)
There is much confusion here:
if you add something in your application layout, it should be rendered for all pages. So the variable should be created everywhere -> that's the application_controller job.
In your application_controller.rb, add:
before_filter :mailing_list
def mailing_list
@newsletter = Newsletter.new
end
And remove your definition of signup
in your Newsletter controller.
精彩评论