I ask for comments in a materialize-css modal view:
<% @contents.each do |content| %>
some form elements
<%=button_to('Comments', new_comment_path, :method => :get, params: { :content_id => content.id }, :class=> 'modal-trigger', 'data-target'=>'modal4'+content.id.to_s) %>
<% end %>
modal=>
<div id="modal4<%=content.id%>" class="modal modal-fixed-footer">
<div class="modal-content">
<%= form_for Comment.new, remote: true do |f| %>
…
…
<%= f.submit 'Send’ %>
<% end %>
CommentsController =>
def create
@comment = Comment.new(comment_params)
end
The values are saved in the db: Rendered comments/create.js.erb (0.0ms)
But: I can't get the modal close again after submit.
create.js =>
Tried with
$('#modal4').closeModal();
$('#modal4').modal('close');
$('modal4<%=@comment.content_id%>').closeModal();
$("modal4<%=@comment.content_id%>").modal('close');
But no success.
Try
$('modal4<%=@comment.content_id%>').modal('hide');
to close the modal.
For more, read http://getbootstrap.com/javascript/#modals-methods
ok. the point was an entry in application.html =>
<base href='http://lvh.me:3000' />
Creating a => XMLHttpRequest cannot load
I end up successfully with... route:
resource :contents do
resources :comments, only: [:new, :create, :update]
end
Calling the modal
<%=button_to('Comment', '#', :method => :get, :class=> 'button button-primary button__slim send__feedback modal-trigger', 'data-target'=>'modal4'+content.id.to_s) %>
the from in the modal
<%= form_for(Comment.new, url: contents_comments_path, remote: true) do |f| %>
...
<%end%>
the comments_controller:
def create
@comment = Comment.new(comment_params)
@comment.update_attributes(rating: params[:rating])
end
and the create.js.erb
$('#modal4<%=@comment.content_id%>').closeModal();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.