title: Undefined method error on class attributes in rails
body: <p>Hi I'm new to Ruby on Rails so please forgive me if the question is somehow stupid.</p>
  
  <p>I'm currently following the guide <a href="https://ihower.tw/rails4/restful-practices.html" rel="nofollow">here</a>.(It's written in Traditional Chinese).</p>
  
  <p>And in that chapter, the author is talking about setting the status of a resource.</p>
  
  <p>First, it edited the app/model/event.rb file</p>
  
  <pre><code>def closed?
    self.status == "CLOSED"
  end
  
  def open?
    !self.closed?
  end
  
  def open!
    self.status = "OPEN"
    self.save!
  end
  
  def close!
    self.status = "CLOSED"
    self.save!
  end
  </code></pre>
  
  <p>Then the config/routes.rb file.</p>
  
  <pre><code>resources :events do
      resource :state, :controller =&gt; 'event_states'
      # ...
  end
  </code></pre>
  
  <p>Then the app/view/events/show.html.erb file and insert the following code.</p>
  
  <pre><code>&lt;p&gt;Status: &lt;%= @event.status %&gt;&lt;/p&gt;
  
  &lt;p&gt;
  &lt;% if @event.closed? %&gt;
      &lt;%= link_to '[Open]', event_state_path(@event ), :method =&gt; :post %&gt;
  &lt;% else %&gt;
      &lt;%= link_to '[Close]', event_state_path(@event), :method =&gt; :delete %&gt;
   &lt;% end %&gt;
  &lt;/p&gt;
  </code></pre>
  
  <p>I understand that it's trying to toggle the status of an event through the POST and DELETE http request, but I get the "NoMethod" error on the show page. Which is understandable(?) cause there's no such variable in the class "event".</p>
  
  <pre><code>undefined method `status' for #&lt;Event:0x007f5e59b3b988&gt;
  
    &lt;% end %&gt;
  &lt;/p&gt;
  &lt;p&gt;Status : &lt;%= @event.status %&gt;&lt;/p&gt;
  
  &lt;p&gt;
  &lt;% if @event.closed? %&gt;
  </code></pre>
  
  <p>Any thoughts on this problem?
  (Please tell me if you need other information)</p>