0

I'm trying to create my first Redmine plugin. Actually i'm trying to create a form in the issue sidebar (the view_layouts_base_sidebar hook) , and i can't find a way to get the current project

To get the current user, we can do this

User.current

Now, i want to get the project of the current issue, do you know how to get it ? as Project.current doesn't exist

Thanks a lot

jan
  • 1,160
  • 1
  • 9
  • 11
user
  • 539
  • 1
  • 11
  • 32

2 Answers2

0

As mentioned in the relevant documentation, simply using

project = context[:project]

should do the trick for you.

I would advise against using Issue.find(context[:request].params[:id]) as it may yield unwanted results. Since the view_layouts_base_sidebar is called in all kinds of contexts, context[:request].params[:id] could be a wiki page id, a project id, a tracker id, etc. Simply passing that to Issue.find() will find no issue in the best case or a totally unrelated issue in the worst case.

I recommend you read about Rails routing, too.

jan
  • 1,160
  • 1
  • 9
  • 11
-1

I got it

issue = Issue.find(context[:request].params[:id])
project = Project.find(issue.project_id)
user
  • 539
  • 1
  • 11
  • 32
  • While this may work in some circumstances, it is sure to yield unwanted results in most others. See my answer for a better solution. – jan Aug 18 '16 at 13:27