EDITED
Tried a lot of solutions, but nothing worked.
Here is code from create.js.erb:
$('<%= j render @website %>').appendTo('#websites').hide().fadeIn();
$("#new_website")[0].reset();
$(".alert").html("<%= escape_javascript(flash[:notice]) %>"); $(".alert").show(300);
Here is my controller:
def create
@website = current_user.websites.new params[:website]
respond_to do |format|
if @website.save
format.html { redirect_to @website, notice: 'Website was successfully created.' }
format.js {
flash[:notice] = 'Website was successfully created.'
render action: 'create'
}
else
format.html { render action: "new" }
format.js { render action: "new" }
end
end
end
HTML of my notice-alerts:
<div class="alert alert-notice">
Can you suggest why it doesn’t work ?
It appears that you are only setting the notice when responding to html requests, not js requests, I think you need something like this: