ruby - Rails 4 - Bootstrap modal form - setup -
i'm trying follow this tutorial setup modal containing nested form in rails 4 app.
i have models project , invite. associations are:
project has_many :invites invite belongs_to :project in views projects folder, have made partial called new_invitation.html.erb
<div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <h3 id="mymodallabel">modal header</h3> </div> <div class="modal-body"> **here comes whatever want show!** </div> <div class="modal-footer"> <button class="btn" data-dismiss="modal" aria-hidden="true">close</button> <button class="btn btn-primary">save changes</button> </div> i'm trying link from project show page, has:
<%= link_to 'invite team mates', new_invitation_path, {:remote => true, 'data-toggle' => "modal", 'data-target' => '#modal-window'} %> <div id="modal-window" class="modal hide fade" role="dialog" aria-labelledby="mymodallabel" aria-hidden="true"></div> in app/javascripts folder, have file called new_invitation.js.erb, with:
$("#modal-window").html("<%= escape_javascript(render 'project/new_invitation') %>"); in application js, have:
//= require bootstrap/modal (slightly different tutorial because use rails 4 , bootstrap sass).
in projects controller, have:
def new_invitation respond_to |format| format.html format.js end end i changed routes put action (although don't understand step):
resources :projects member "new_invitation" => "projects/new_invitation", as: :new_invitation end resources :invites end there problem link path in attempt above. i'm not sure why, error message suggests using:
new_invitation_project_path when try that, error says:
undefined method `render' #<#<class:0x007fa2b2138bf0>:0x007fa2a04a1308> i saw in comments in tutorial, tried rewriting js file as:
$("#modal-window").html("<%= escape_javascript(render :partial => 'project/new_invitation') %>"); i tried same error message. can see might need replicate success tutorial seems have other users?
the problem member route defined here.
resources :projects member "new_invitation" => "projects/new_invitation", as: :new_invitation end end
the member route generated is
new_invitation_project /projects/:id/new_invitation(.:format) projects/new_invitation#new_invitation the controller action projects/new_invitation#new_invitation doesn't exist.
the mapping should in format controller#action. so, should be
get "new_invitation" => "projects#new_invitation", as: :new_invitation or better,
get :new_invitation use rake routes | grep invitation see route generated.
in new_invitation action, you're rendering js response. so, rails new_invitation.js.erb inside app/views/projects. have move file app/javascripts right location mentioned above.
and there's issue new_invitation.js.erb code. _new_invitation.html.erb resides in views/projects/ directory. so, should modify
$("#modal-window").html("<%= escape_javascript(render 'projects/new_invitation') %>"); otherwise, you'll missing template error since looking template in project directory. make sure have _new_invitation.html.erb partial defined in app/views/projects directory.
to render modal, need display modal using modal method.
$('#modal-window').modal('show'); your new_invitation.js.erb should this.
$("#modal-window").html("<%= escape_javascript(render 'projects/new_invitation') %>"); $('#modal-window').modal('show'); hope helps!
Comments
Post a Comment