I'm quiet new in ruby on rails. I'm trying to develop an app which uses ActiveModel objects only in controllers without saving. Unfortunately after clicking the submit button I get an error. The aim of this app is to perform some calculations and show the results. How can I do that?
Routing Error No route matches [POST] "/shugarcalc"
app/models/sugar_amount.rb
class SugarAmount
include ActiveModel::Model
attr_accessor :l, :h, :b, :tw, :tf
VALID_NUMBER_REGEX= /[0-9]{1,2}([,][0-9]{1,2})?/
validates :l, presence: true, format: { with: VALID_NUMBER_REGEX }, length: { maximum: 10 }
validates :h, presence: true, format: { with: VALID_NUMBER_REGEX }, length: { maximum: 10 }
end
config/routes.rb
SimpleDesign::Application.routes.draw do
root 'static_pages#home'
resources :sugar_amount, only: [:new, :create]
match '/shugarcalc', to: 'shugar_amounts#shugar', via: 'get'
end
app/controllers/shugar_amounts_controller.rb
class ShugarAmountsController < ApplicationController
def sugar
@sugar_amount=SugarAmount.new
end
def create
@sugar_amount = SugarAmount.new(params[:sugar_amount])
/here i want to use some functions /
redirect_to root_url
/this is temporary, just to see if anything happens /
end
end
app/views/sugar_amounts/sugar.html.erb
<%= form_for(@sugar_amount) do |f| %>
<%= f.label :l, "eggs" %>
<%= f.text_field :l %><br>
<%= f.label :h, "flour [mm]" %>
<%= f.text_field :h %><br>
<%= f.submit "Reduce!" %>
<% end %>