I have a create.js.erb, I want make this: if the user click to create button, the site load index partial.
$('.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 create.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@eventsif the action is a success then update events/_index to call@events.eachinstead of@event.each.