Undefined method error

Added by Brandon Dixon almost 13 years ago

I am trying to add a feature to our local Redmine instance (and release back out to the community) so that users can select whether or not they want categories to be required by default. I have modified the language (en) to include my setting and then went to the projects view to add my line to make a check box appear and pull the text from the language file. I am going solely based off of what all the other checkboxes seem to be doing but get this:

ActionView::TemplateError (undefined method `default_require_category' for #<Class:0xb6941ef0>) on line #11 of settings/_projects.rhtml:
8: <%= check_box_tag 'settings[sequential_project_identifiers]', 1, Setting.sequential_project_identifiers? %><%= hidden_field_tag 'settings[sequential_project_identifiers]', 0 %></p>
9:
10: <p><label><%= l(:setting_default_require_category) %></label>
11: <%= check_box_tag 'settings[default_require_category]', 1, Setting.default_require_category %></p>
12:
13: <%= submit_tag l(:button_save) %>
14: <% end %>

I understand that I need to define the method I am using at Setting.default_require_category, but I have no clue where to do this. I have searched through the whole Redmine project to identify where the sequential_project_identifiers method was defined, but I have only found it in the language file and the view file. Any help would be greatly appreciated.

Replies (4)

RE: Undefined method error - Added by Eric Davis almost 13 years ago

The language file just defines the text strings Redmine uses. config/settings.yml holds the default Settings data.

Eric

RE: Undefined method error - Added by Brandon Dixon almost 13 years ago

So would I add my new method to the config/settings.yml file? It doesn't look like that would be the proper place to define based on the contents of the file.

RE: Undefined method error - Added by Eric Davis almost 13 years ago

Brandon Dixon wrote:

So would I add my new method to the config/settings.yml file? It doesn't look like that would be the proper place to define based on the contents of the file.

It is not the the proper place to reconfigure Settings but it is the proper place to add new settings. Basically Redmine will load it's Settings from this file as the default settings and then use the specific values in the database (settings table) to override the yml file. So you would need to define a new setting value in settings.yml and then build a user interface around that value in order to save it to the database. It looks like you have already started on the UI by editing the view file above. r2449 shows how I added a new setting called 'openid' to Redmine. This should help point you in the right direction.

Let me know if you have any questions.

Eric Davis

RE: Undefined method error - Added by Brandon Dixon almost 13 years ago

Thanks a lot!

I solved all my problems, but one. It has to do with the conditional in the issue.rb model file.

I am trying to check my setting variable to see if the category should be set to required. If it is then I would like it to add that :category be required in the validate function.

if Setting.default_require_category?
validates_presence_of :subject, :priority, :project, :tracker, :author, :status, :category
else
validates_presence_of :subject, :priority, :project, :tracker, :author, :status
end

I know there are cleaner ways to do this, but the general idea does not seem to work correctly.

(1-4/4)