Sha256: 63c20f8bd18cd88a5d8db5b5ea747e210adcea650529aa421ef16c864186efa6

Contents?: true

Size: 1.16 KB

Versions: 2

Compression:

Stored size: 1.16 KB

Contents

module GoGamification
  module ApplicationHelper


    # Create a form to reward someone for something.
    #
    # rewardable - A model that is rewardable (e.g. a user)
    # options    - A Hash of options:
    #              :for      - A model that is rewarding (e.g. an article)
    #              :redirect - A String describing a URL to redirect to.
    def reward rewardable, options
      rewarding = options[:for]
      redirect  = options[:redirect]

      form_tag Gamification::Engine.routes.url_helpers.rewards_path, method: :post do
        concat hidden_field_tag 'reward[rewarding_type]', rewarding.class.name
        concat hidden_field_tag 'reward[rewarding_id]', rewarding.id
        concat hidden_field_tag 'reward[rewardable_type]', rewardable.class.name
        concat hidden_field_tag 'reward[rewardable_id]', rewardable.id
        concat hidden_field_tag 'checksum', Checksum.generate(
          [rewarding.class.name, rewarding.id, rewardable.class.name, rewardable.id]
        )

        if redirect
          concat hidden_field_tag 'redirect_url', redirect
        end

        concat submit_tag I18n.t 'go_gamification.complete'
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
go_gamification-0.0.7 app/helpers/go_gamification/application_helper.rb
go_gamification-0.0.6 app/helpers/go_gamification/application_helper.rb