I have two views quotation.html.erb
and calculate.html.erb
. I have quotation.html.erb
set up correctly. Data will be retrieved from tints
entity when the drop down menu is chosen correctly from the form in quotation.html.erb
. It will then generate a quotation by rendering a view, generate.html.erb
This is what I have for my tints_controller.rb
def calculator
render 'calculator'
end
def quotation
render 'quotation'
end
def generate
// a lot of formulas here
// @measurements will get the measurement from tint entity
if current_page?(:controller => 'tints', :action => 'quotation') //this is my question
@measurements_front = @measurements.front
@measurements_side = @measurements.side
@measurements_rear = @measurements.rear
@measurements_roof = @measurements.roof
else
@measurements_front = params[:front]
@measurements_side = params[:side]
@measurements_rear = params[:rear]
@measurements_roof = params[:roof]
end
end
Now I am trying to create a page, calculate.html.erb
, for users to input value in the text_field
instead of selecting from the available data from the drop down menu. User will input values (as in integer) manually (front, side, rear, roof) and submit the form to get quotation from the view generate.html.erb
So here is my question. I am trying to use current_page?
helper to see what page the user is in. If the user is in quotation.html.erb
, it will get the @measurements
from the table. If the user is in calculate.html.erb
, it will get the :front, :side, :rear: roof
.
I tried several methods and I still get the error undefined method
current_page?' . Does
. Does
current_page?` still exists in Rails 5 or we have to define it by ourselves?
Also, I have my routes.rb
set up as below.
//More routes here
get '/quotation/tints' => 'tints#quotation', :as => 'tints_quotation'
get '/calculator/tints' => 'tints#calculator', :as => 'tints_calculator'
post '/quotation/tints/generate' => 'tints#generate', :as => 'generate_tints_quotation'
post '/calculator/tints/generate' => 'tints#generate', :as => 'generate_tints_calculator'
current_page?
still exists in Ruby on Rails 5.
But it is a view helper method and therefore not available in the context of a controller.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.