2017-08-31 24 views
0

我需要訪問params,它位於模塊中,位於模塊幫助中。例如。Rails如何訪問模塊中的「params」方法,它位於輔助模塊內部

module ApplicationHelper 
    module ExampleModule 
    extend self 

    def an_example_method 
     //access params here 
    end 
    end 
end 

如何做到這一點?

+0

如果你使用它,你就需要將PARAMS傳遞到方法的單。更好的問題是,你爲什麼試圖做到這一點。 – max

+0

我不會用作單身人士。我希望在控制器中使用該方法作爲完全限定的名稱,就像「ExampleModule.an_example_method」一樣。 – rplaurindo

回答

0
在我看來,這樣做將是通過PARAMS這樣

模塊ApplicationHelper 模塊ExampleModule 延伸自我的最簡單的事情

def an_example_method(params) 
    params.each do |param| 
    puts param 
    end 
    //access params here 
end 

末 結束

形成了現在的coltroller你可以像這樣調用an_example_method方法

ExampleModule.an_example_method(params) 

我希望這有助於