I keep getting a undefined method `model_name’ for NilClass:Class.
In the layout file: [application.html.erb]
<section id="featured">
<%= render 'subscribers/new' %>
</section>
In the form partial: [views > subscribers > _new.html.erb]
<%= form_for @subscriber, :url => subscribe_path do |f| %> [THIS LINE PRODUCES THE ERROR]
<div class="field">
<%= f.text_field :email %>
</div>
<div class="actions">
<%= f.submit 'Add me to the list' %>
</div>
<% end %>
In the subscribers controller: [controllers > subscribers_controller.rb]
def new
@subscriber = Subscriber.new
end
I’m a beginner at ROR, and I’ve looked around StackOverflow, but can’t find any answers for my specific case.
What path are you hitting when you are seeing this error?
If you are navigating to any path other than
/subscribers/newthen@subscriberwill beniland the form will throw the error that you are seeing. You are rendering a form via a partial in your view layout, that layout is rendered (presumably) throughout the app. Thus@subsriberwon’t always be set.