0

I have problem: I want to call modal with errors if there are errors in registration or sign in form.

So how to call js from controllers or how I should do this ?

Here is my controller:

   def create
    @user = User.new(params[:user])
     if @user.save
   # Handle a successful save.
     else
   render :js => ('#login').modal('show')
   end
  end

Something like this, but in right way.

5
  • What type of language are you using to do that? Commented Jun 11, 2012 at 15:38
  • It seems to be Ruby on Rails. render :js => "('#login').modal('show')" Commented Jun 11, 2012 at 15:48
  • Yes, you are right. It's not correct, so it doesn't matter. I want to use this twitter.github.com/bootstrap/javascript.html#modals, but I don't know how. Commented Jun 11, 2012 at 15:49
  • What about that? stackoverflow.com/questions/10300064/… Commented Jun 11, 2012 at 15:53
  • I saw this, but don't know what is haml and hoped, that there is another way, more understandable for me. Commented Jun 11, 2012 at 15:57

1 Answer 1

1

Make sure you are creating and declaring your modal correctly:

HTML:

<head>
   <link href="path/to/bootstrap.css" rel="stylesheet">
   <script src="path/to/jquery.js"></script>
   <script src="path/to/bootstrap-modal.js"></script>
</head>

<div id="login" class="modal hide fade in" style="display: none;">
   <div class="modal-header">             
      ...
   </div>
   <div class="modal-body">              
      ...
   </div>
   <div class="modal-footer">
      ...
   </div>
</div>

JS:

$('#login').modal({ ... });

Rails (not my speciality, mostly going off your example code):

def create
   @user = User.new(params[:user])
   if @user.save
      # Handle a successful save.
    else
      render :js => "('#login').modal('show');"
   end

**Note that I added double quotes around the render :js argument as specified in the documentation.

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

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.