$('.content').html("<%= escape_javascript(render(:partial => "events/index")) %>");
If I use this, I get error @objectname.each is wrong, I think it's empty, because in the cr开发者_开发技巧eate.js.erb file I only call the partial, and I think I must call index method somehow. It's right?
def create
@event = Event.create(params[:event])
respond_to do |format|
if @event.save
format.html { redirect_to(events_url) }
format.js
else
format.html { render :action => "new" }
format.js
end
end
end
the error message:
ActionView::Template::Error (undefined method `each' for #<Event:0x00000102182830>):
1: - @event.each do |events|
2: %h3.title= events.name
You need to provide the partial with the events it should be rendering. Right now you're just providing it with the single event, @event.
Populate @events
if the action is a success then update events/_index to call @events.each
instead of @event.each
.
def create
@event = Event.create(params[:event])
respond_to do |format|
if @event.save
format.html { redirect_to(events_url) }
format.js {
@events = Event.all
}
else
format.html { render :action => "new" }
format.js
end
end
end
精彩评论