0

我正在尝试为博客文章作者创建一个描述页面。我创建了一条路线:

mount Monologue::Engine, at: '/blog'

#create routes for monologue
Monologue::Engine.routes.draw do
    get 'p/:name', to: 'authors#show', as: :author
end

我在 app/controllers/monologue 中创建了一个控制器:

class Monologue::AuthorsController
    def show
        puts "in show method"
    end
end

我不断收到此错误:

undefined method `action' for Monologue::AuthorsController:Class

长话短说:如何在独白中生成控制器?

4

1 回答 1

-1
Monologue::Engine.routes.draw do
  get '/posts/:author_id', to: "posts#author_posts", as: "author_posts"
end

class Monologue::PostsController < Monologue::ApplicationController
  def author_posts
    @posts = Monologue::Post.where(:user_id => params[:author_id],).order(created_at: :desc)
    @author = Monologue::User.find_by_id(params[:author_id])
  end
end

这就是添加控制器操作的方式。

于 2016-01-04T20:32:54.550 回答