I did some research and couldn't find a suitable answer so I'm reaching out.....
Using Rails 3.1 and trying to crea开发者_如何转开发te a post for a user. When I go to create a test post I get the error:
Missing template events/create, application/create with {:locale=>[:en, :en],
:formats=>[:html], :handlers=>[:coffee, :erb, :builder]}
Is this a template or should I adjust my routes?
Thanks in advance for any help.
From the log you provided here, you should be posting to Events controller's create method.
The following is copied from your repo:
def create
@event = current_user.events.build(params[:event])
if @event.save
flash[:success] = "Event Shared"
redirect_to root_path
#else
# render 'pages/about'
end
#@event = Event.new what I had before
#@title = "Create An Event"
end
So if @event.save
failed, there's no redirect and the render is commented out. So by default, rails 3.1 will try to find the view file in the following order: events/create, application/create (it matches your log)
With failing event.save, you would most likely render "new"
so that it will use events/new.html.erb for the view file. (of course this is not a must, you could render anything you want or even redirect if you like)
(Hope that what I am viewing on the repo isn't a modified one :) )
Probably you would need:
def create
@event = current_user.events.build(params[:event])
if @event.save
flash[:success] = "Event Shared"
redirect_to root_path
else
render :new
end
end
It will use error messages you already have in a view.
精彩评论