title: Ruby On Rails. Change controller's variable through view and render updated view
body: <p>I'm very beginner in RoR and even in web-programming. So I guess my question is so easy for many developers!</p>
  
  <p>I'm implementing simple weeks calendar, it should have day's names and two "buttons" - 'next week' and 'previous week'. That's all for beginning!</p>
  
  <p>I have controller with index action:</p>
  
  <pre><code>    def index
  
        @today = Date::today
        @monday = @today.beginning_of_week
        @sunday = @today.end_of_week
  
        @currentweek = @monday..@sunday    
     end
  </code></pre>
  
  <p>and two other actions:</p>
  
  <pre><code>  def go_next_week
        @monday = @sunday + 1
        @sunday = @monday.end_of_week
    end
  
    def go_prev_week
        @sunday = @monday - 1
        @monday = @sunday.beginning_of_week
    end
  </code></pre>
  
  <p>index view code:</p>
  
  <pre><code>&lt;div class="wrapper"&gt;
    &lt;table class="data"&gt;
      &lt;thead&gt;
      &lt;tr class="month-names"&gt;      
        &lt;td&gt;&lt;%= form_tag(work_days_go_prev_week_path, method: "get") do %&gt;
              &lt;%= submit_tag(l(("workdays_show_prev" + period).to_sym)) %&gt;
          &lt;% end %&gt;
        &lt;/td&gt;
        &lt;td&gt;&lt;%= render :partial =&gt; 'days_names_header' %&gt;&lt;/td&gt;
        &lt;td&gt;&lt;%= form_tag(work_days_go_next_week_path, method: "get") do %&gt;
              &lt;%= submit_tag(l(("workdays_show_next" + period).to_sym)) %&gt;
          &lt;% end %&gt;
        &lt;/td&gt;
      &lt;/tr&gt;
      &lt;/thead&gt;
    &lt;/table&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>And the routes file:</p>
  
  <pre><code>RedmineApp::Application.routes.draw do
    match 'work_days/go_next_week'            ,:to =&gt; 'work_days#go_next_week',           via: [:get]
    match 'work_days/go_prev_week'            ,:to =&gt; 'work_days#go_prev_week',           via: [:get]
    match 'work_days/(:action(/:id))',via: [:get], :controller =&gt; 'work_days'
  end
  </code></pre>
  
  <p>The main goal on that stage in short terms is:</p>
  
  <ul>
  <li><p>Controller has a Date variables 'monday','sunday' and Range
  'currentweek'</p></li>
  <li><p>Index view shows table of days according that    variables</p></li>
  <li><p>Index view has 2 "buttons": 'next week' and 'previous    week'</p></li>
  <li><p>Clicking on this buttons should change Controller's    variables</p></li>
  <li><p>Index view should "refresh" with changed Controller's    variables</p></li>
  </ul>
  
  <p>This code isn't working. I got such error in log when clicking on 'Previous month' button:</p>
  
  <blockquote>
    <p>Started GET
    "/work_days/go_prev_week?tf8=%E2%9C%93&amp;commit=Previous+week" for
    127.0.0.1 at 2015-12-09 14:00:27 +0600 Processing by WorkDaysController#go_prev_week as HTML Parameters:
    {"utf8"=>"✓","commit"=>"Previous week"} Current user: admin (id=1)
    Completed 500 Internal Server Error in 3ms (ActiveRecord: 0.2ms)</p>
    
    <p>NoMethodError (undefined method `-' for nil:NilClass)</p>
  </blockquote>