Question

I'm creating a controller hook of my issues_controller on Redmine. I followed this tutorial.

The question is I couldn't access the checkbox (That I created through a hook on view page) value to set my controller variable. Follow my code

_new_hook.html.erb

<div class="splitcontentright">
  <% @user = User.current %>
  <b><br><label for="mail_checker_issue"><%= check_box_tag "mail_checker_issue", 1, @user.pref.always_check_email %><%= l(:send_email) %></label></b>
</div>

issues_email_patch.rb

Rails.configuration.to_prepare do
  require_dependency 'issue'
  class Issue
    attr_accessor :mail_checker_issue
  end
end

controller_hook.rb

module Redmine_send_emails
  module Hooks
    class Issues_controller_hook < Redmine::Hook::ViewListener
      def controller_issues_new_before_save(context={})
        context[:issue].mail_checker_issue = context[:params][:mail_checker_issue]
      end
    end
  end
end

Until where I've checked the hook works well. I've debugged the application and it called correctly the controller_hook method, but I couldn't find the value of my checkbox within the params.

What's wrong? How to do it?

Was it helpful?

Solution

You don't see your checkbox value because you display it before labelled_form_for @issue so it does not belongs to the form.

You can place it here (there are 2 place for hook)

You can try to implement gem deface - I managed to use it in Redmine plugin.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top