-1
在我的Rails代碼庫中,有一個特定方法的動作調用之前,但我無法調用它。RubyOnRails +無法調用IF條件的before_action方法
示例代碼: -
ControllerCode
class HomeController < ApplicationController
before_action :set_country, only: [:index, :update]
def index
puts "Inside Index - #{@country}"
end
def update
if true && book_my_ride
puts "Inside Update - BookMyRide"
end
end
def book_my_ride
puts "Inside BookMyRide - #{@country}"
end
def set_country
@country = "SampleCountry"
end
end
當更新方法被調用,因爲之前的動作, - set_country被調用。
但是,當控制達到具有'book_my_ride'的IF條件時 - 系統不會爲book_my_ride調用'set_country'方法。
您是否期望'set_country'在該場景中被調用兩次?這不是它的工作原理。 –
@SergioTulentsev - 明白了你的觀點。錯誤地,我爲before_action添加了book_my_ride – Rubyist