简体   繁体   English

Link_to Ruby on rails-未定义的方法`post_path'

[英]Link_to Ruby on rails - undefined method `post_path'

I have this code: 我有以下代码:

<%= @r2_blog_posts = Refinery::Blog::Post.recent(2) %>
<%= link_to(@r2_blog_posts.first) do %>
    <%= image_tag(@r2_blog_posts.first.teaser_first_img) %>
<% end %>

I'm getting this error for second line: undefined method `post_path' for #<#:0x0000000841c168> teaser_first_img is returning src attribute of the first image in teaser 我在第二行收到此错误:#<#:0x0000000841c168>的未定义方法`post_path'teaser_first_img正在返回预告片中第一张图片的src属性

I have not used this engine, but I think that the posts - is a nested or namespaced resource. 我没有使用过此引擎,但我认为帖子-是嵌套或命名空间的资源。 So you need to know at first path for post: rake routes and then use something like: link_to blog_post_path(@r2_blog_posts.first) - change blog_post_path to actual path 因此,您需要首先了解发布路径: rake routes ,然后使用类似以下内容的链接: link_to blog_post_path(@r2_blog_posts.first) -将blog_post_path更改为实际路径

You must have defined on your routes something like 您必须在路线上定义以下内容

resources :posts

or 要么

match 'post/:id' => 'posts#show', :as => :post

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM