lundi 17 décembre 2018

inside modal form_for submit not working in rails?

when i submit form submit doesn't go to reject_permission. error is URL something wrong like this

http://localhost:3000/permissions?utf8=%E2%9C%93&_method=patch&authenticity_token=hThIutas1j22xz6lNlBGZ%2BcK1h9GFacea9Jb%2BZ8ex0KSX74kz6NqV0atyoohRsuyvnzk%2FYdPS3yw4jCjbXFeag%3D%3D&id=4&%2Fpermissions%2Freject_permission%5Brejected_reason%5D=&commit=Reject

my view

 <%= link_to 'Reject',  '#', 'data-target' => "#editpermission",'data-toggle' => 'modal' ,
'data-id' => "#{permission.id}",class: "edit btn btn-danger btn-sm" %>
  <%= render 'edit_permission_modal'%>
 <script type="text/javascript">

    $(document).on("click",".edit",function(){
      var permissionId = $(this).data('id');


      $(".modal-body #permissionId").attr("value",permissionId);


    })
   </script>

edit_permission_modal.html.erb

<div class="modal fade" id="editpermission" role="dialog">
            <div class="modal-dialog">
            <!-- Modal content-->
            <div class="modal-content">
               <div class="modal-header">
               </div>
               <div class="modal-body">
                  <%= form_for reject_path,multipart: true, method: :patch do |f| %>
                  <input type="hidden" name="id" id="permissionId" class="form-control" value="">
                  <%=f.text_field :rejected_reason,class: "form-control"%>
               </div>
               <div class="modal-footer">
                  <%= f.submit 'Reject', class: "btn btn-danger btn-sm" %>
               </div>
               <%end%>
            </div>
            </div>
</div>

controller

    class PermissionsController < ApplicationController
     before_action :set_permission, only: [:show, :edit, :update, :destroy,:accept_permission]
    def reject_permission
            puts "reject_permission"
        end
end

routes

resources :permissions
patch 'permissions/reject_permission',to: 'permissions#reject_permission', as: :reject

Output

Aucun commentaire:

Enregistrer un commentaire