簡體   English   中英

Rails View haml“未定義的方法” link_to

[英]Rails View haml “undefined method” link_to

Ruby,Rails 3,新手

我正在擴展用於類分配的工作Rails應用程序(顯示電影),因此基本的管道工作正常。

我在routes.rb中添加了一個條目-

match "/movies/directed_by/:director" => "movies#directed_by"

我的耙路然后有一個條目

/movies/directed_by/:director(.:format) {:controller=>"movies", :action=>"directed_by"}

請注意,沒有“路徑”,也沒有指定HTTP方法(例如GET)

對於其他(自動生成的“ Rails模型”)路由, 指定路徑和動詞。

我有一個控制器方法

def directed_by

  # some code

end

我在其中添加了一個View文件../app/Views/show.html.haml

= link_to 'Find Movies With Same Director', directed_by(@movie.director)

引發運行時錯誤-

NoMethodError in Movies#show

Showing /home/saasbook/hw3/hw3_rottenpotatoes_rjf/app/views/movies/show.html.haml where line #22 raised:

undefined method `directed_by' for #<#<Class:0xc564594>:0xc532198>

所以我的問題是,現在我是否要調整routes.rb和/或查看haml以將所有內容捆綁在一起?

歡迎所有提示。

在航線上:

match "/movies/directed_by/:director" => "movies#directed_by", :as => :movie_direct_by

然后在您看來:

= link_to 'Find Movies With Same Director', movie_direct_by_path(@movie.director)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM