1

My controller is:

def create
  @group = Group.new(params[:group])

  @group.company=current_user.company
  respond_to do |format|
    if @group.save
      format.html { redirect_to(@group, :notice => 'Group was successfully created.') }
      format.js
    else
      flash.now[:error][email protected]_messages
      format.html { render :nothing => true }
      format.js
    end
  end
end

create.js.erb is:

$('<%= escape_javascript(render(:partial => @group))%>').appendTo('#groups');
$("#new_group")[0].reset();

2 Answers 2

7
$(".flashnotice").html("<%= escape_javascript(flash[:notice]) %>");  
$(".flashnotice").show(300);

You have to add these two lines in your create.js.erb file. Replace .flashnotice with the selector for your flash HTML element; e.g., the class name of your flash <div>.

Sign up to request clarification or add additional context in comments.

1 Comment

I think with this approach you want <% flash.discard %> after showing the notice to keep the notice from appearing on subsequent pages.
-4

I think you just need to say <%= flash[:notice] %> somewhere in your erb file.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.