I want to update the submit form via ajax without reloading the page and update the presentation accordingly. I tried different methods and could not, like I'm new to rails.
Here is the situation.
In modal
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
In the form field.
<%= 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 %>
Create action
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
and finally in the view I want to change
<p class="instructions count-instruction text-center"> <%= @words.count %> </p>
It has been a long time updating this with AJAX, but not every time. Is anyone there to help? Thanks in advance.
source share