No commit activity in last 3 years
No release in over 3 years
Helpful generators for Redmine plugin authors.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.3.7

Runtime

~> 3.2.12
 Project Readme

Redmine Generators

Build Status Gem Version

Helpful generators for Redmine plugin authors.

Crash Course

Recreate the Redmine plugin tutorial using the redmine:plugin and redmine:scaffold generators:

$ git clone https://github.com/redmine/redmine.git; cd redmine
$ echo "development:\n  adapter: sqlite3\n  database: db/dev.db" > config/database.yml
$ echo 'gem "redmine-generators", group: :development' >> Gemfile.local
$ bundle --without rmagick   # Or whatever
$ rails g redmine:plugin polls
$ rails g redmine:scaffold polls poll question yes:integer no:integer
$ rake generate_secret_token db:migrate redmine:plugins:migrate
$ REDMINE_LANG=en rake redmine:load_default_data

Add a vote method to the Poll model in plugins/redmine_polls/app/models/poll.rb:

def vote(answer)
  increment(answer == "yes" ? :yes : :no)
end

Create a vote action for the PollsController in plugins/redmine_polls/app/controllers/polls_controller.rb:

def vote
  @poll.vote params[:answer]
  flash[:notice] = "Voted #{params[:answer]}" if @poll.save && !request.xhr?
  respond_with(@poll) do |format|
    format.js { render action: :show }
  end
end

Create a member route in plugins/redmine_polls/config/routes.rb for the new vote action:

scope "/projects/:project_id" do
  resources :polls do
    post "vote", on: :member
  end
end

Add the vote method to the respond_to :js and before_filter :find_poll statements:

respond_to :js, only: [:show, :new, :create, :edit, :update, :destroy, :vote]
# ...
before_filter :find_poll, only: [:show, :edit, :update, :destroy, :vote]

Add voting links to plugins/redmine_polls/app/views/polls/show.html.erb:

<p>
  <b>Vote:</b>
  <%= link_to "Yes", vote_poll_path(@poll, answer: "yes"), method: :post %> |
  <%= link_to "No", vote_poll_path(@poll, answer: "no"), method: :post %>
</p>

And basically the same for plugins/redmine_polls/app/views/polls/show.js.erb but using remote: true for AJAX links:

<p>
  <b>Vote:</b>
  <%= link_to "Yes", vote_poll_path(@poll, answer: "yes"), method: :post, remote: true %> |
  <%= link_to "No", vote_poll_path(@poll, answer: "no"), method: :post, remote: true %>
</p>

Finally, add a :vote_polls Redmine permission to the :polls project module in plugins/redmine_polls/init.rb:

  project_module :polls do
    # ...
    permission :vote_polls, polls: [:vote]
  end

Start the rails server if you haven't already with rails s. Grant voting access to whichever roles you'd like at http://localhost:3000/roles/permissions, create a project with the :polls module enabled, and start polling!

Available Generators

  • redmine:plugin
  • redmine:project_menu
  • redmine:project_module
  • redmine:resource_route
  • redmine:scaffold
  • redmine:scaffold_controller
  • redmine:translation

This project rocks and uses MIT-LICENSE.