redmine 插件使用

插件使用
product
1、生成插件
rails generate redmine_plugin products
2、修改插件信息
plugins/products/init.rb 
3、生成插件模型
rails generate redmine_plugin_model products product question:string yes:integer no:integer 
4、数据迁移
rake redmine:plugins:migrate
5、添加模型方法
plugins/polls/app/models/product.rb
6、生成控制器
rails generate redmine_plugin_controller Products products index vote
7、实现控制器方法
plugins/polls/app/controllers/products_controller.rb
8、编辑视图
plugins/polls/app/views/products/index.html.erb
9、添加路由
plugins/products/config/routes.rb
10、国际化
plugins/products/config/locales/.
11、扩展菜单
plugins/products/init.rb
Redmine::Plugin.register :redmine_polls do
  [...]


  menu :application_menu, :polls, { :controller => 'polls', :action => 'index' }, :caption => 'Polls'
end
12、项目菜单
Redmine::Plugin.register :redmine_polls do
  [...]


  permission :polls, { :polls => [:index, :vote] }, :public => true
  menu :project_menu, :polls, { :controller => 'polls', :action => 'index' }, :caption => 'Polls', :after => :activity, :param => :project_id
end
点击后项目菜单可见
def index
  @project = Project.find(params[:project_id])
  @polls = Poll.find(:all) # @project.polls
end
13、添加新的权限
plugins/polls/init.rb
permission :view_polls, :polls => :index
permission :vote_polls, :polls => :vote


class PollsController < ApplicationController
  unloadable


  before_filter :find_project, :authorize, :only => :index


  [...]


  def index
    @polls = Poll.find(:all) # @project.polls
  end


  [...]


  private


  def find_project
    # @project variable must be set before calling the authorize filter
    @project = Project.find(params[:project_id])
  end
end


权限国际化
plugins/polls/config/locales
增加.yml文件
en:
  permission_view_polls: View Polls
  permission_vote_polls: Vote Polls






14、创建项目模块
编辑init.rb文件改变权限声明
project_module :polls do
    permission :view_polls, :polls => :index
    permission :vote_polls, :polls => :vote
end
15、插件样式
plugins/polls/assets/stylesheets/voting.css
在视图中增加
<% content_for :header_tags do %>
    <%= stylesheet_link_tag 'voting', :plugin => 'polls' %>
<% end %>


16、设置页面标题
<% html_title "Polls" %>



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值