Question

First, I explain what I want to do : when user enters wrong values in sign_in or sign_up popup form(Bootstrap modal) I should call $("#sign_up").show(); or $("#login").show();.

So, I need to call js from views: I see it like this:

  <%= devise_error_messages! //here call $("#sign_up").show(); %>

or other way, but almost the same, but withous devise_error

  <% if @user.errors.any? %>
<%"eval('$("#sign_up").show();')"%> 

or how it should be...

I should rewrite my registration or not ?

Correct me please, I can't get how do it.

No correct solution

OTHER TIPS

If I understand the question you do not need to call the modal. Just do not hide it after the page loads. That is, there must be something like this:

<% if @user.errors.any? %>
  <div id="myModal" class="modal">
<% else %>
  <div id="myModal" class="modal hide">
<% end %>
    #your modal here
  </div>

But in general I would advise to use Ajax and respond with js in create action that render form inside your modal:

#create action
respond_to do |format|
  if @user.save
    ...
  else
    ...
    format.js { render action: "new" }
  end


#new.js.erb
$('#myModal').html("<%= j render 'form' %>");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top