Now, let's consider that the polls are defined at project level (even if it's not the case in our example poll model). So we would like to add the Polls tab to the project menu instead.Open init.rb and replace the line that was added just before with these 2 lines:

The second line adds our Polls tab to the project menu, just after the activity tab.The first line is required and declares that our 2 actions from PollsController are public. We'll come back later to explain this with more details.

Restart the application again and go to one of your projects:

If you click the Polls tab, you should notice that the project menu is no longer displayed.To make the project menu visible, you have to initialize the controller's instance variable @project.

For now, anyone can vote for polls. Let's make it more configurable by changing the permission declaration.We're going to declare 2 project based permissions, one for viewing the polls and an other one for voting. These permissions are no longer public (:public => true option is removed).

Edit init.rb to replace the previous permission declaration with these 2 lines:

Of course, some code needs to be added to the PollsController so that actions are actually protected according to the permissions of the current user.For this, we just need to append the :authorize filter and make sure that the @project instance variable is properly set before calling this filter.

Retrieving the current project before the #vote action could be done using a similiar way.After this, viewing and voting polls will be only available to admin users or users that have the appropriate role on the project.

For now, the poll functionality is added to all your projects. But you way want to enable polls for some projects only.So, let's create a 'Polls' project module. This is done by wraping the permissions declaration inside a call to #project_module.

When starting the application, plugin assets are automatically copied to public/plugin_assets/redmine_polls/ by Rails Engines to make them available through your web server. So any change to your plugin stylesheets or javascripts needs an application restart.

Then, append the following lines at the end of app/views/polls/index.html.erb so that your stylesheet get included in the page header by Redmine: