Flyingbeaver Flyingbeaver - 1 month ago 21
Ruby Question

Launch modal from controller

i'm trying to show a modal window (using jquery ui dialog) to the user from my controller.

For example :

def create
if params[:id]
#do something
else
#show a modal window with a partial as content
end


Thx for your help =)

Answer

This is a fix, but probably will work for you

Controller

def create
  if params[:id]
    #true code
  else
    render :new
    @dialog = true
  end    
end

on you new.html.erb

<% if @dialog %>
  <%= #dialog code %>
<% else %>
  <%= #normal code %>
<% end %>

Hope it works.

UPDATE

If what I asked you in comment is correct then you can do this

in your new.html.erb you can do this

<% form_for @product do |f| %>
  <% if @product.errors %>
    <%= #dialog code %>
  <% end %>
<% end %>