如何在rails中的独白博客引擎中创建新的控制器

时间:2015-12-04 21:43:39

标签: ruby-on-rails ruby-on-rails-4 rails-engines monologue

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

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

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

1 个答案:

答案 0 :(得分:-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

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