title: attr_accessor and attr_reader not working in Rails 4
body: <p>I am trying to migrate an application to rails 4 and ruby2.</p>
  
  <p>In my model <code>Product</code>, I had this : </p>
  
  <pre><code>attr_accessor :name, :age, :price
  </code></pre>
  
  <p>which I switched to :</p>
  
  <pre><code>attr_reader :name, :age, :price
  </code></pre>
  
  <p>In my view I have this : </p>
  
  <pre><code>  %td.small
      = number_with_precision(@p.get_last_usd_price.to_f, precision: 2, delimiter: ",", strip_insignificant_zeros: true)
  </code></pre>
  
  <p>Everything worked fine with rails 3.2 and <code>attr_accessor</code>. But now I have an issue in <code>get_last_usd_price</code> :</p>
  
  <pre><code>  def get_last_usd_price
      price = 0.0
      puts "--------------------"
      puts self.inspect          #---&gt; prints a #&lt;product&gt; with all the correct attributes
      puts
      puts self.name.inspect     #---&gt; prints nil
      puts @name.inspect         #---&gt; prints nil
      puts "--------------------"
      # blah blah
    end
  </code></pre>
  
  <p>Basically, all the variables are nil when I try to access them but they are correctly saved into the object instance.</p>
  
  <p>What am I doing wrong? How can I fix this?</p>
  
  <p>Thanks in advance.</p>
  
  <p>Edit : The controller</p>
  
  <pre><code>  def detail_product
      @p = Product.find(params[:product_id]) if params[:product_id].present?
      if !@p.present? then
        flash[:error] = 'No product id'
        redirect_to  :action =&gt; :products
      end
    end
  </code></pre>