2017-06-17 42 views
1

可能是一個新手問題,但它讓我卡住了。Rails控制器不傳遞參數到模型

我的導軌程序應該採取一個出發城市,目的地城市,然後搜索一個與搜索條件匹配的旅行數據庫。不幸的是,我不知道爲什麼我的控制器不傳遞參數給我「,在模型M中調用該方法

在我的控制,我有:。

@OneLeg = Trip.OneLeg(params[:origin], params[:destination]) 

,並在我的模型我有:

def self.OneLeg(sorigin, sdestination) 
    Trip.where(["origin = ? and destination = ?", sorigin, sdestination]) 
end 

當我嘗試查看網頁出現錯誤:

wrong number of arguments (given 0, expected 2)

不能完全確定是什麼導致了這個問題。

非常感謝您的幫助!

+0

你會在哪一行發現錯誤?分享你的表格,可能你的參數沒有這些鍵值。你在日誌中看到了什麼? –

+1

params是零,這就是爲什麼 –

回答

0

可能是一個強大的參數問題。嘗試發佈您的Contollers私有方法(tripParams或類似),我們可以提供更多幫助。

很可能你會需要允許params並通過params方法訪問它們。

相關問題