Note that there are some explanatory texts on larger screens.

plurals
  1. PORuby on Rails : NoMethodError
    primarykey
    data
    text
    <p>I am a beginner in ROR .I faced a problem that when I test code on one book. I follow it stage by stage, but the error show up...</p> <p>NoMethodError in CaculatorController#calculate</p> <pre><code>undefined method `[]=' for nil:NilClass </code></pre> <p>Rails.root: /home/toth4321/calculator</p> <pre><code>app/controllers/caculator_controller.rb:4:in `set_charset' </code></pre> <p><strong>Controller</strong></p> <pre><code>class CaculatorController &lt; ApplicationController before_filter:set_charset def set_charset @headers['Content-Type'] = 'text/html; charset=GB2312' end def calculate if request.post? arg1 = convert_float(:arg1) arg2 = convert_float(:arg2) op = convert_operator(:operator) @result = op.call(arg1, arg2) end end private def convert_float(name) Float (params[name]) end def convert_operator(name) case params[name] when "+" then proc {|a,b| a+b} when "-" then proc {|a,b| a-b} when "*" then proc {|a,b| a*b} when "/" then proc {|a,b| a/b} end end end </code></pre> <p><strong>Views</strong></p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;title&gt;簡單的網頁計算器&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;%= form_tag(:action =&gt; :calculate) %&gt; &lt;%= text_field_tag(:arg1, @params[:arg1], :size =&gt;3) %&gt; &lt;%= select_tag(:operator, options_for_select(%w{+ - * /})), @params[:operator])) %&gt; &lt;%= text_field_tag(:arg2, @params[:arg2], :size =&gt;3) %&gt; &lt;%= submit_tag("送出") %&gt; &lt;% end_form_tag %&gt; &lt;b&gt;&lt;%= @result %&gt;&lt;/b&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>can somebody help me? Thanks a lot!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload