1

I'm creating a Redmine plugin with a menu tab. Follow the guide

http://www.redmine.org/projects/redmine/wiki/Plugin_Tutorial

I can add a menu tab in file init.rb as below:

  permission :polls, { :polls => [:index, :vote] }, :public => true
  menu :project_menu, :polls, { :controller => 'polls', :action => 'index' }, :caption => 'Polls', :after => :activity, :param => :project_id

The menu tab is OK for PollsController.

But I create a new controller (for example, ArticlesController) in the same plugin. There's a link in polls#index to go to articles#new. But articles#new don't appear in the menu, it appear as I didn't create menu. How can I use the 'Polls' menu tab for ArticlesController.

I tried:

class ArticlesController < ApplicationController
    menu_item :pivot_table
    ....
end

and

  permission :polls, { :polls => [:index, :vote] }, :public => true
  permission :polls, { :articles => [:index, :vote] }, :public => true
  menu :project_menu, :polls, { :controller => 'polls', :action => 'index' }, :caption => 'Polls', :after => :activity, :param => :project_id

but no luck.

Here my routes.rb:

RedmineApp::Application.routes.draw do

  resources :projects do
    resources :polls, :only => [:index]
    resources :articles, :only => [:new, :create]
  end

  resources :articles, :except => [:show]
end

Pleae help me. My redmine version is 2.3.2. Thank you.

vietstone
  • 8,784
  • 16
  • 52
  • 79

2 Answers2

0

Not sure if it's what you are asking for, but to get 2 tabs in the project menu, you could try :

Redmine::MenuManager.map :project_menu do |menu|
  menu.push :polls, { :controller => 'polls', :action => 'index' }, :param => :project_id, :caption => 'Polls', :after => :activity
  menu.push :articles, { :controller => 'articles', :action => 'new' }, :param => :project_id, :caption => 'Articles', :after => :activity
end
Nanego
  • 1,890
  • 16
  • 30
0

I found my problem. It's the permission in init.rb

My error configuration:

  permission :polls, { :polls => [:index, :vote] }, :public => true
  permission :polls, { :articles => [:index, :vote] }, :public => true
  menu :project_menu, :polls, { :controller => 'polls', :action => 'index' }, :caption => 'Polls', :after => :activity, :param => :project_id

The name "permission :polls" is duplicated. I'm wrong. I think that ":polls" is name. But it's permission's name. I change to another name, it's OK.

  permission :polls, { :polls => [:index, :vote] }, :public => true
  permission :articles_permission, { :articles => [:index, :vote] }, :public => true
  menu :project_menu, :polls, { :controller => 'polls', :action => 'index' }, :caption => 'Polls', :after => :activity, :param => :project_id
vietstone
  • 8,784
  • 16
  • 52
  • 79