Link to home
Start Free TrialLog in
Avatar of Denis Orozco
Denis OrozcoFlag for United States of America

asked on

How to get POST to show a page on ruby and rails

hi there,
Currently my application does display the page i want but when i click the button of submit i get this error:

Routing Error
No route matches [POST] "/result"
Try running rake routes for more information on available routes.

my routes.rb looks like this:
Adder::Application.routes.draw do
  resources :posts
#...
End

and my controller looks like this:
class PostsController < ApplicationController
  def index
   
  end
 
  # result method - fetch data and compute the sum
  def result

# Fetch the form values
    @first = params[:first].to_i
    @second = params[:second].to_i

# Compute the sum
    @sum = @first + @second
  end

end

my question is how do enter the post record inside the routes.rb  and where does my result page needs to live?
Thanks,
COHFL
Avatar of Rameshwar Vyevhare
Rameshwar Vyevhare
Flag of India image

Use form_tag element and add create action in controller, calculate result in create action then redirect to index page to show result.

Best luck.
Avatar of Denis Orozco

ASKER

rameshwar007,
Thanks for your reply but the redirect part is the one i'm having trouble with on my controller i have def result but is not going to my result.html.erb where dos this files goes? under  ...\app\views\name_controller\ or where exactly?
This file will reside in the same posts but you need to add route for that action then can redirect to result page.
Hope this short note will help you.
ok if my controller has an entry like this
Def result
end

what would be the entry in the route table?
ASKER CERTIFIED SOLUTION
Avatar of Rameshwar Vyevhare
Rameshwar Vyevhare
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial