controller 里的代码:
def create
@event = Event.new(params[:event])
respond_to do |format|
if @event.save
# format.html { redirect_to @event, notice: 'Event was successfully created.' }
# format.json { render json: @event, status: :created, location: @event }
format.js { render :layout => false } # new add
else
# format.html { render action: "new" }
# format.json { render json: @event.errors, status: :unprocessable_entity }
format.js { render :layout => false,:status => 406 } # new add
end
end
end
然后 create.js.erb 里
alert("<%= escape_javascript @event %>")
可以确定 alert 是一定可以执行,不过由于取不到@event,会报 500 错误
取不到这个@event ,求教是何缘故