为Alchemy CMS创建自定义留言簿模块 [英] Creating a custom Guestbook Module for Alchemy CMS
问题描述
我正在尝试使用Alchemy CMS框架在Rails站点中构建留言簿模块.用Alchemy构建模块的文档似乎没有太多方法,所以我只是从此页面.
I'm trying to build a guestbook module within a Rails site using the Alchemy CMS framework. There doesn't appear to be much in the way of documentation for module building with Alchemy, so I'm just going off of this page.
我已经创建了两个控制器,管理员将使用一个名为guestbook_controller.rb的控制器,并将其放置在app/controllers/admin下
I've created two controllers, one that admins will use called guestbook_controller.rb and placed this under app/controllers/admin
module Admin
class GuestbookController < Alchemy::Admin::ResourcesController
def index
"index"
end
end
end
和另一个供访客访问的app/controllers/guestbook_controller.rb
and another for guest to access under app/controllers/guestbook_controller.rb
class GuestbookController < ActionController::Base
def index
"index"
end
end
我的意图是,留言簿帖子将显示在Alchemy中已经存在的页面之一下,并且还将在该页面上显示一个表单.
My intention is that Guestbook posts will be displayed under one of the pages already within Alchemy and a form will also be displayed on this page.
留言簿模型如下:
class GuestbookEntry < ActiveRecord::Base
attr_accessible :location, :message, :name
end
我的路线文件如下所示:
My routes file looks like the following:
resources :guestbook
namespace :admin do
resources :guestbook
end
mount Alchemy::Engine => '/'
,并且在配置下有一个名为authorization_rules.rb的文件,如下所示: 授权做
and I have a file called authorization_rules.rb under config that looks like: authorization do
role :admin do
has_permission_on :guestbook, :to => [:manage]
end
end
我遇到的第一个问题是,转到路由/admin/guestbook会给我错误您未获得授权",但是授权规则文件应由我的初始化程序调用,所以为什么我得到了这个错误?
The first problem that I'm encountering is that going to the route /admin/guestbook gives me the error 'You are not Authorized', but the authorization rules file should be being called by my initalizer, so why am I getting this error?
# Registering guestbook module in Alchemy CMS
Alchemy::Modules.register_module(YAML.load_file(File.join(File.dirname(__FILE__), '../..', 'config/guestbook_module.yml')))
# Loading authorization rules and register them to auth engine instance
Alchemy::AuthEngine.get_instance.load(File.join(File.dirname(__FILE__), '../..', 'config/authorization_rules.rb'))
推荐答案
授权问题很容易. 您只需要写:
The problem with the authorization is easy. You just need to write:
has_permission_on :admin_guestbook, :to => [:manage]
我注意到的另一件事:您的前端GuestbookController应该继承自Alchemy :: BaseController.
Another thing I noticed: Your frontend GuestbookController should inherit from Alchemy::BaseController.
并且您应该确保Alchemy不会缓存要在其上呈现留言簿条目的页面.您可以通过使用page_layouts.yml中的cache: false
选项来实现页面布局.
And you should make sure that your page you want to render the guestbook entries on, must not be cached by Alchemy. You can do this by using cache: false
option in the page_layouts.yml for your page layout.
这篇关于为Alchemy CMS创建自定义留言簿模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!