title: update database when click button using ruby on rails
body: <p>I am new using Ruby On Rails so this question may seem stupid. I've been searching a lot tutorial and sort of understand what I could do, but what the code looks like exactly? how i should implement this and where to put them still confuse me.</p>
  
  <p>I have a database called note which has two attributes, :note whose type is text and a foreign key called user_name whose type is string. In the main.html.erb, I have my main page and also a note pad whose is a text area. here's part of main</p>
  
  <pre><code>    &lt;div class="four columns" id="note"&gt;
        &lt;textarea id="area" style="width:250px; height:300px;" placeholder="Your notes starts here"&gt;&lt;%= @note %&gt;&lt;/textarea&gt;
        &lt;div id="clear" class="primary btn pretty"&gt;&lt;a href="#"&gt;Clear&lt;/a&gt;&lt;/div&gt;
        &lt;div class="secondary btn pretty"&gt;&lt;%= link_to 'Save', controller: 'main', action: 'update_note', :remote =&gt; true, :method =&gt; :put %&gt;&lt;/div&gt;
      &lt;/div&gt;
  </code></pre>
  
  <p>By the way, I'm using Gumby. so My button is called "Save". I want the user to input their note in the txtfiled and when they click the "save" button, it will update the note database in the row according to the user_name. 
  So my question is, should I write a action on main_controller or notes_controller. How should I do it. Sample could would be much helpful since I tried different way and it is really frustrating. 
  I tried putting the code in the main_controller like this:</p>
  
  <pre><code>    def update_note
  @note = Note.find_by(user_name: session[:user_name])
  
  respond_to do |format|
    if@note.update_attributes(params[:note])
      format.html { redirect_to @note, :notice =&gt; 'Note was successfully updated.' }
      format.js
    else
      format.html { render :action =&gt; "edit" }
      format.js
    end
  end
  end
  </code></pre>
  
  <p>as well as tried to put code in notes_controller. but I get "No route match"</p>
  
  <p>I totally mess up. And it'd due tomorrow! thanks for any help. It's so nice to refers me some link of tutorial but the anything related to my code would be more helpful!</p>
  
  <p>Thanks!</p>