mercredi 15 mars 2017

Rails add new and edit form in bootstrap modal

I'm new with Runy on Rails. Now I'm trying to make a simple ToDo List app with bootstrap. Everything works but I tryed to render my New task form to modal window and it's crashed. Here is my _form partial code:

  <div id="myModal" class="modal fade" role="dialog">
    <div class="modal-dialog">
      <!-- Modal content-->
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title">Modal Header</h4>
        </div>      
      </div>
        <div class="modal-body">
          <h1>New Task</h1>
          <%= form_for @task, :html => {class:"form-horizontal"} do |f|%>
             <!-- Here is form code -->
          <% end %>
          <%= link_to 'Back', tasks_path %>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
      </div>
    </div>

And here is my Index.html.erb:

<div class="container-fluid">
    <div class="row">
        <h1 class="text-left">Task List</h1>
        <%= button_to 'New Task', new_task_path, :class =>"btn btn-success pull-right", :method => "get", data: {'data-toggle' => "modal", 'data-targe' => "#myModal"} %>
    </div>
    <div class="row button-margin ">
    <% @tasks.each do |task| %>
            <div class="panel <%= task_status(task) %>">
                <div class="panel-heading">
                    <%= task.title %>
                    <p class="pull-right"><%= task.dueDate %></p>
                </div>
                <div class="panel-body">    
                    <h3><%= task.body %></h3>
                </div>
            </div>
        <% end %>
    </div>

    <%= render "tasks/form" %>
</div>

So when trying to start my index page I get an error "First argument in form cannot contain nil or be empty". Whats wrong with my code? And how can I pass an exsisting task to form for Edit action?

Aucun commentaire:

Enregistrer un commentaire