ruby on rails - Calculator using checkbox values -


i new ruby on rails.. please me figure out.. thank u.. :)

i trying create simple calculator

i getting wrong number of arguments (1 0)

calculator_controller.rb

      class calculatorcontroller < applicationcontroller                    def calculate                         pasta = params [:pasta]                         noodles = params [:noodles]                         @result = pasta.to_i + noodles.to_i                         redirect_to result_path                    end            end 

/views/page/calculator.html.erb

             <%= form_tag({:controller => "calculator", :action => "calculate"}, :method => "post") %>                       <div>                              <%= check_box_tag 'pasta', '100' %>menu item 1                       </div>                       <div>                              <%= check_box_tag 'noodles', '200' %>menu item 2                       </div>                       <div>                               <%= submit_tag('submit', :disable_with => 'submitting...')%>                        </div>             <% end %> 

/views/calculator/result.html.erb

    <div>        <%= @result %>     </div> 

class calculatorcontroller < applicationcontroller                    def calculate                         pasta = params [:pasta]                         noodles = params [:noodles]                         @result = pasta.to_i + noodles.to_i                         redirect_to result_path                    end            end 

here redirecting result_path. value in @result lost. if want keep value of @result, can keep in session or pass using params or use flash or render view going use render view on here.

there space between params , [:pasta]. thats why getting error. remove space, work you.

class calculatorcontroller < applicationcontroller                        def calculate                             pasta = params[:pasta]                             noodles = params[:noodles]                             @result = pasta.to_i + noodles.to_i                             render 'result'                        end                end 

in view

<div>        <%= @result %>     </div> 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -