Rails 4 - Bootstrap modal form - setup

爱⌒轻易说出口 提交于 2019-12-04 23:16:29

The problem is with the member route defined here.

resources :projects do
  member do
    get "new_invitation" => "projects/new_invitation", as: :new_invitation
end

end

The member route generated is

new_invitation_project GET  /projects/:id/new_invitation(.:format)  projects/new_invitation#new_invitation

The controller action projects/new_invitation#new_invitation doesn't even exist.

The mapping should be in the format controller#action. So, it should be

get "new_invitation" => "projects#new_invitation", as: :new_invitation

or even better,

get :new_invitation

Use rake routes | grep invitation to see the route generated.

In the new_invitation action, you're rendering a js response. So, rails will look for new_invitation.js.erb inside app/views/projects. You have to move your file from app/javascripts to the right location as mentioned above.

And there's another issue with your new_invitation.js.erb code. The _new_invitation.html.erb resides in views/projects/ directory. So, you should modify it to

$("#modal-window").html("<%= escape_javascript(render 'projects/new_invitation') %>");

otherwise, you'll get a Missing Template error since its looking for the template in the project directory. Make sure that you have _new_invitation.html.erb partial defined in app/views/projects directory.

To render the modal, you need to display the modal using the modal method.

$('#modal-window').modal('show');

Your new_invitation.js.erb should look like this.

$("#modal-window").html("<%= escape_javascript(render 'projects/new_invitation') %>");
$('#modal-window').modal('show');

Hope this helps!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!