以下是情况说明:
在模态框中。
def new
@new_entry = current_user.notes.build
@words = current_user.notes
@notes_false_list = current_user.notes.where(known: false).order("title").group_by { |note| note.title[0] }
@notes_true_list = current_user.notes.where(known: true).order("title").group_by { |note| note.title[0] }
end
在查看表单代码时。
<%= form_for @new_entry, :html => {:class => 'home-form without-entry clearfix'} do |f| %>
<%= f.text_field :title, placeholder: 'Squirrel', autofocus: true, class: 'title-field pull-left' %>
<%= f.submit '', class: 'btn home-add without-entry' %>
<% end %>
创建操作
def create
@new_note = current_user.notes.build(new_note_params)
if @new_note.save
@notes_list = current_user.notes.count
unless @new_note.user.any_entry
@new_note.user.toggle!(:any_entry) if @notes_list >= 50
redirect_to root_url
end
else
redirect_to root_url
end
end
最后,在视图中我想要进行更改
<p class="instructions count-instruction text-center">
<%= @words.count %>
</p>
我花了很多时间尝试使用AJAX更新,但每次都失败了。有人可以帮忙吗?先谢谢了。