I'm getting the error
ArgumentError in PagesController#home, wrong number of arguments (0 for 1)
but I don't know why. I have a Users
model from Devise, and a Dplan
model, where dplan belongs_to :user
and a user has_many :dplans
. I'm trying to set up my site so that you can create a new dplan on the home page. My home page view is this:
<% if user_signed_in? %>
<h1>Hello <%= current_user.name %>! <h1>
<%= form_for @dplan do |f|%>
<div class="field">
<%= f.text_area :name %>
</div>
<div class="actions">
<%= f.submit "Submit" %>
</div>
<% end %>
<% else %>
<h1>DPlanner</h1>
<p>
This is the home page for DPlanner.
</p>
<%= link_to "Sign up now!", new_user_registration_path, :class => "signup_button round" %>
<% end %>
This is dplans_controller.rb:
class DplansController < ApplicationController
def create
@dplan = current_user.dplans.build(params[:dplan])
if @dplan.save
flash[:success]="Dplan created!"
redirect_to root_path
else
render 'pages/home'
end
end
def destroy
end
end
And here is pages_controller.rb:
class PagesController < ApplicationController
def home
@title = "Home"
@dplan = Dplan.new if user_signed_in?
end
end
I don't understand why I'm getting this error message - the only argument needed on the page is dplan, which I define in the pages controller. Help!
Here is dplan.rb:
class Dplan < ActiveRecord::Base
attr_accessible :name
belongs_to :user
validates :name, :presence=>true, :length => { maximum => 30 }
validates :user_id, :presence =>true
end