Project

General

Profile

Conserving project path inside a Redmine plugin

Added by Tudor Cornea over 13 years ago

Hello

I have been trying to create an uploads plugin, and I'm experiencing some difficulties with the project path preservation:

First, I created the plugin using ./script/generate redmine_plugin Upload

I want the plugin to be displayed in the 'Projects' menu, and so I edited the init.rb file

  project_module :uploads do
     permission :view_uploads  , :uploads => :index, :require => :member
     permission :create_uploads, :uploads => :new, :require => :member
  end

  menu :project_menu, :uploads, {:controller => 'uploads', :action => 'index'},   {:caption => 'Uploads', :after => :activity, :param => :project_id }

  activity_provider :uploads, :default => false, :class_name => ['Upload', 'UserUploads']

The problem was that when I clicked on the "Upload" tab, the project page disappeared, so I had to pass it somehow to
the index action of the controller.
http://localhost:3001/redmine/uploads?project_id=test

This didn't seem like a good way, so I edited the routes.rb file

/config/routes.rb file for the plugin :

#custom routes for this plugin
ActionController::Routing::Routes.draw do |map|
  map.resources :projects, :only => [] do |project|
   project.resources :uploads, :shallow => true, :new => { :preview => :post}, :member => {:lock => :post} do |upload|
#    upload.resources : :upload, :shallow => true, :only => [:create, :update] 
    end
  end
end

Now, the path looks like this:

http://localhost:3001/redmine/projects/test/uploads

The 'index' view contains a link to the new action

<p><%= link_to "New Upload", {:action => 'new'} -%></p>

..Which gives the following path http://localhost:3001/redmine/uploads/new

The 'new' contains a back link, that should point to 'index'
<%= link_to 'Back', {:controller => 'uploads', :action => 'index'} -%>

The problem is that when i click on the link, it redirects me to http://localhost:3001/redmine/uploads
, instead of http://localhost:3001/redmine/projects/test/uploads.

Somehow, the project path was lost along the way.

The error is :

ActiveRecord::RecordNotFound in UploadsController#index

Couldn't find Project without an ID

Also, I would like to know what is the best way to preserve the project path when navigating inside my plugin.