Project

General

Profile

Hook and form_for

Added by Diego Sousa over 15 years ago

I need some help with forms in hooks, i need create a form to insert in some pages of redmine, the problem is this, when i create the form and execute i get every time the same error

undefined method `protect_against_forgery?' for #<TranslateHook:0xb552a19c>

Anyone can help me with this?

Thanks!


Replies (2)

RE: Hook and form_for - Added by Diego Sousa over 15 years ago

I forgot to post the code that make this error,

i made a plugin to translate some fields of redmine and i need a form to insert this translates in the database, well, than i put a simple form_for like the on bellow to test and when the page render i get the error "undefined method `protect_against_forgery?' for ..."

form_for TranslatedField.new do |f|
           f.text_field :language
            f.text_field :field
            f.text_field :translated
end

Anyone can help me with this?
Thanks!

RE: Hook and form_for - Added by Eric Davis over 15 years ago

Rails uses protect_against_forgery to make sure the form was posted from the same website. You can disable it by implementing that method in your hook class and returning false:

class MyHookClass < Redmine::Hook::ViewListener
  def protect_against_forgery?
    false
  end
end

Example: http://github.com/edavis10/redmine-budget-plugin/tree/master/lib/budget_project_hook.rb

Eric

    (1-2/2)