How to open a form within a modal with Rails 4 and Foundation?

Asked

Viewed 409 times

0

I have a product register in Rails. I am using Zurb-Foundation 5 as a lib in the Front-End. How do I call an inclusion form within a Modal Window in the Foundation. I created a partial with the form and tried to insert it into the div to be called at the moment of the click but it doesn’t work. Trying to be more specific to facilitate. I have the URL:

localhost:3000/products 

The index action should already list all available products and at the same time show the include button. When you click the button, you should open the modal with the damn inclusion form. I wanted to do CRUD operations without changing the URL to /new, /product/:id and so on. What I could do?

  • A bit difficult without seeing the code, but come on: you created your partial? (following _) and then just use: <%= render partial: "partial" %>

  • Yes friend. I created the partial. The problem of this approach that you mentioned, is the following:

1 answer

1

I don’t know the Zurb-Foundation, but try the following:

Configure the action new controller to render no layout:

def new
  [...]
  render :new, layout: :none
end

This will make Rails send only partial HTML, without the entire template (<html><head>...</head><body>...</body></html>).

As I told you, I don’t know the Zend-Foundation, but I think it should work if you can get this HTML and "paste" into the modal.

Another way would be to create the form via Javascript itself and make the post request for the action "create" (or other action you want). But for that you’ll have to deactivate the authentication token for that action (see in the documentation).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.