I'm trying to make a simple calculator that converts farenheit to celsius, using Ruby on Rails. I keep getting the error "Wrong number of arguments (1 for 2)" after I enter some input value. This app has been alot more difficult than it should be. I've been fixing errors as they come up, but can't figure this one out. Other posts I've read are much different and more elaborate than this simple app I'm trying to make. Thanks for any help.
The controller ...
class CalculatorController < ApplicationController
def calculate
@farenheit = params[:temperature]
unless @farenheit.blank?
@farenheit = Temperature.calculate({ :farenheit => @farenheit})
end
@celsius = (@farenheit - 32) * (5.0 / 9.0)
end
private
## Strong Parameters
def user_params
params.require(:farenheit)
end
end
The model...
class Temperature < ActiveRecord::Base
# attr_accessible :farenheit
validates_presence_of :farenheit
validates_numericality_of :farenheit
end
The view...
<h1>Temperature Calculator</h1>
<%= form_tag(calculator_calculate_path, method: "get", action: "calculate") do |form|%>
<p>Please enter a temperature in degrees Farenheit</p>
<%= text_field_tag 'temperature', @farenheit %></p>
<%= submit_tag 'Convert' %>
<h2>Result: </h2>
<h3> <% @celsius %> </h3>
<% end %>
The stack trace (first 10 lines)...
activerecord (4.1.6) lib/active_record/relation/calculations.rb:109:in `calculate'
C:in `calculate'
app/controllers/calculator_controller.rb:6:in `calculate'
actionpack (4.1.6) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (4.1.6) lib/abstract_controller/base.rb:189:in `process_action'
actionpack (4.1.6) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.1.6) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
activesupport (4.1.6) lib/active_support/callbacks.rb:113:in `call'
activesupport (4.1.6) lib/active_support/callbacks.rb:113:in `call'
Temperature.calculate
the class methodcalculate
, is it something you have defined or are you using Active Record's class method? If you have defined it, post it here as well.