0

私はRuby on Railsの初心者です。保存せずにコントローラーでのみ ActiveModel オブジェクトを使用するアプリを開発しようとしています。残念ながら、送信ボタンをクリックするとエラーが発生します。このアプリの目的は、いくつかの計算を実行して結果を表示することです。どうやってやるの?

ルーティング エラー 一致するルートがありません [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 %>
4

1 に答える 1