插件使用
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" %>
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" %>