Creating a custom Guestbook Module for Alchemy CMS

扶醉桌前 提交于 2019-12-25 03:04:29

问题


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.

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

and another for guest to access under app/controllers/guestbook_controller.rb

class GuestbookController < ActionController::Base
  def index
    "index"
  end
end

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.

The guestbook model looks this:

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 => '/'

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

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'))

回答1:


The problem with the authorization is easy. You just need to write:

has_permission_on :admin_guestbook, :to => [:manage]

Another thing I noticed: Your frontend GuestbookController should inherit from Alchemy::BaseController.

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.



来源:https://stackoverflow.com/questions/11710115/creating-a-custom-guestbook-module-for-alchemy-cms

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!