Project

General

Profile

Setting object returning nil

Added by erick andrade about 10 years ago

Hi!

I'm trying to program a redmine plugin using plugin Settings facility.

In my init.rb i have:

require 'redmine'
Redmine::Plugin.register :searcher do
  name 'Searcher plugin'
  author 'xxx'
  description 'xxx'
  version '0.0.1'
  url 'xxx'
  author_url 'xxx'

  settings :default => {
    'abc' => 'xxx',
    'abc2' => 'yyy'
  }, :partial => 'settings/searcher_settings'

  menu :top_menu, :searcher, { :controller => 'searcher', :action => 'index' }, :caption => 'Searcher'
end

In controller:

class SearcherController < ApplicationController
  unloadable

  def index
    @abc = Setting.plugin_searcher['abc']
    render :action => 'index'
  end
end

The problem is that Setting.plugin_searcher['abc'] in controller always returns nil.

In the view, if a put:

<%= settings['abc'] %>

i receive the error:

"Error (undefined local variable or method `settings'"

Can somebody help me?

Thank you!


Replies (5)

RE: Setting object returning nil - Added by Mischa The Evil about 10 years ago

Hi Erick,

I've mocked up a similar plugin, corrected the errors and added some demonstration equations using plugin settings values. I've uploaded the resulting demonstration plugin to https://github.com/MischaTheEvil/searcher.
Feel free to fork it or otherwise make use of it...

I hope this helps to clear up the things a bit.

Greetings,

Mischa.

RE: Setting object returning nil - Added by erick andrade about 10 years ago

Hi Mischa,

i installed your version, and i'm getting the following error in both controller and view:

View:
ActionView :: Template :: Error (can not convert Symbol into Integer)

Controller:
TypeError (can not convert Symbol into Integer)

My redmine version is 2.3.2-0, from Bitnami.

Do you know what might be happening?

Thank you!

RE: Setting object returning nil - Added by erick andrade about 10 years ago

I don't know what is the problem, but i've tested your plugin in another redmine installation (version 2.5.2/bitnami) and it works perfectly!

The same plugin in my production redmine (version 2.3.2 with several plugins installed) doesn't work.

I will perform some tests of environment ... I know the code is right!

Thank you very much, Mischa!

RE: Setting object returning nil - Added by Mischa The Evil about 10 years ago

I've just pushed some syntactic changes into a branch (fix/1_44245-cant_convert_Symbol_into_Integer). It's at https://github.com/MischaTheEvil/searcher/tree/fix/1_44245-cant_convert_Symbol_into_Integer. Can you please try that code and report back the results?
Please provide some more info about your environment (OS, Ruby, Rails, etc. [see eg. submissions]) and some log snippets also. What other plugins are you using?

FTR: I'm not able to reproduce the errors you are reporting using the code on the master branch nor the code in the newly pushed branch on a test deployment of Redmine source:/trunk@133661

1 Details about my test environment...

Regards,

Mischa.

RE: Setting object returning nil - Added by erick andrade about 10 years ago

Hi Mischa!

It's working fine now!

My original code had syntax errors, but i don't know the reason for '(can not convert Symbol into Integer)' errors in your initial version of searcher, using :symbols.

Here's the output of 'ruby scripts/about':

bash-3.2# ruby script/about 

Environment:
  Redmine version                2.3.2.stable
  Ruby version                   1.9.3-p448 (2013-06-27) [i686-linux]
  Rails version                  3.2.13
  Environment                    production
  Database adapter               Mysql2
Redmine plugins:
  redmine_auto_percent           0.0.1
  redmine_auto_watch             1.0.0
  redmine_ckeditor               1.0.16
  redmine_custom_workflows       0.0.4
  redmine_email_notification_content_filter 0.0.2
  redmine_impasse                1.2.2
  redmine_meetings               0.2.4
  redmine_pipeline_plugin        1.0.0
  redmine_send_mails             0.2.23x
  redmine_tab                    0.4.0
  redmine_wiki_books             0.0.3
  redshares                      1.0.0
  scrum2b                        2.0
  searcher                       0.0.1
  under_construction             0.0.1
  unread_issues                  0.0.1

Thank you, Mischa!

    (1-5/5)