sploiber
sploiber

Reputation: 621

How to open new Rails window in sidebar

I am using Rails 3/Bootstrap/JQuery UI. I have a create action which requires the user to enter some parameters before submitting. I have tried a Javascript JQuery UI Dialog Modal Form, but that doesn't make use of the already-written action code. The problem is that the user doesn't like having a completely new window open (and then having to hit Back)

So I would like to open the action, but do so in a sidebar, rather than a new window.

What is the best practice for this in Rails 3?

Adding more clarification. The "action" I meant is a modal dialog where I collect the parameters which are needed for the create. I would like to put that "modal dialog" into a sidebar. Instead, right now, I open the "modal dialog" as a completely new window, and then the user clicks Create, and the new object is created.

I think my main question is - how do I open "new window in a sidebar"?

Added edit: Here is the code for the button the user is going to push: (to add a Cat to an existing Client)

<%= link_to "New Cat", new_client_cat_path(@client), :class => "btn btn-primary btn-large" %>

Now, here is cats/new.html.erb:

<h2>New Cat</h2>
<%= render "form" %>
<%= link_to "Cancel", @client, :class => "btn btn-primary btn-large" %>

and then here is cats/_form.html.erb:

<%= form_for [@client, @cat] do |f| %>
<%= f.error_messages %>
<%= f.submit @submit_label, :class => "btn btn-primary btn-large" %>
<% end %>

What I want is for "new.html.erb" - the form to get the user's OK - to pop up in a sidebar, as opposed to opening a brand new window. I want to be able to put the "new.html.erb" into a small box which is located on the main page.

Upvotes: 0

Views: 309

Answers (1)

Ravi Sankar Raju
Ravi Sankar Raju

Reputation: 2950

If the create form is static, have it already, and on click make it visible using javascript. make an ajax call to create using

<%= form_for @model, :remote => true do |frm| %>
    ...
    ...
<% end %>

in the action create the object, and render :nothing => true or update only parts of the page that is required

Upvotes: 0

Related Questions