我在materialize-css模式视图中请求评论:
<% @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 %>
模态=&GT;
<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 =&gt;
def create
@comment = Comment.new(comment_params)
end
值保存在db中: 渲染注释/ create.js.erb(0.0ms)
但是:提交后我无法再次关闭模态。
create.js =&gt;
尝试
$('#modal4').closeModal();
$('#modal4').modal('close');
$('modal4<%=@comment.content_id%>').closeModal();
$("modal4<%=@comment.content_id%>").modal('close');
但没有成功。
答案 0 :(得分:0)
尝试
public void readUsersSugarDB() {
// SUGAR DB TEST
try {
List<User> users = User.listAll(User.class);
for (int i = 0; i < users.size(); i++) {
User userObject = users.get(i);
Logger.i(userObject.name.toString());
Logger.i(userObject.toString());
}
//Integer userCount = User.getTableName(User.class);
Logger.i("Users list", users);
} catch (Exception e) {
Logger.e("Sugar_db_exception", e.getMessage());
}
}
关闭模态。
如需了解更多信息,请阅读http://getbootstrap.com/javascript/#modals-methods
答案 1 :(得分:0)
确定。这一点是application.html =&gt;中的一个条目。
<base href='http://lvh.me:3000' />
创建a =&gt; XMLHttpRequest无法加载
我最终成功... 路线:
resource :contents do
resources :comments, only: [:new, :create, :update]
end
调用模态
<%=button_to('Comment', '#', :method => :get, :class=> 'button button-primary button__slim send__feedback modal-trigger', 'data-target'=>'modal4'+content.id.to_s) %>
模态中的from
<%= form_for(Comment.new, url: contents_comments_path, remote: true) do |f| %>
...
<%end%>
comments_controller:
def create
@comment = Comment.new(comment_params)
@comment.update_attributes(rating: params[:rating])
end
和create.js.erb
$('#modal4<%=@comment.content_id%>').closeModal();