ruby on rails - How to call javascript from controllers? -


i have problem: want call modal errors if there errors in registration or sign in form.

so how call js controllers or how should ?

here controller:

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

something this, in right way.

make sure creating , declaring 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 speciality, going off example code):

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

**note added double quotes around render :js argument specified in documentation.


Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -