How to send on a render your message from the controller hook? something like flash [: error] = "Message". <- With this method does not work, redmine falls from 500.

Hook

module Integration class ControllerIssuesNewBeforeSaveHook < Redmine::Hook::ViewListener def controller_issues_new_before_save(context={}) # Получаем данные из формы project_id = context[:issue].project.custom_field_values[0].value.to_i if (project_id == 0 || project_id.blank?) flash[:error] = "Error" # Пока всё упадет с 500 redirect_to :back end end end end 

Mistake

 NameError (undefined local variable or method flash' for #<Integration::ControllerIssuesNewBeforeSaveHook:0x0000000410b298>): plugins/integration/lib/integration/controller_issues_new_before_save_hook.rb:16:incontroller_issues_new_before_save' lib/redmine/hook.rb:61:in block (2 levels) in call_hook' lib/redmine/hook.rb:61:ineach' lib/redmine/hook.rb:61:in block in call_hook' lib/redmine/hook.rb:58:intap' lib/redmine/hook.rb:58:in call_hook' lib/redmine/hook.rb:91:incall_hook' app/controllers/issues_controller.rb:139:in create' lib/redmine/sudo_mode.rb:63:insudo_mode' 
  • Did not work with Redmine, but what if instead of flash use context[:flash] ? - D-side
  • lied throws error NoMethodError (undefined method []=' for nil:NilClass): находил подобный вариант: context[:controller].flash[:notice] << 'something to append to the flash message' но в этом случае кидает: NoMethodError (undefined method << 'for nil: NilClass): - Ravil
  • Well, this is progress, there is even a flash object. Try to hook there with a debugger and see what is there for the object. Perhaps ["notice"] instead of [:notice] needed? - D-side

1 answer 1

You go from the wrong end, patch the Issue model and put your validation check. Your error will be displayed as standard error_messages_for in redmine