Configuration

pickhardt edited this page Feb 27, 2013 · 8 revisions

The configuration options for Forem are explained beneath. These usually live in config/initializers/forem.rb.

User class

To specify the class that represents users in your system, use the user_class option:

Forem.user_class = "User"

The user class's instances should respond to 'to_s' for the user's name, and 'email' for use by Gravatar.

NOTE: previously this option accepted a Class object, but that has been deprecated due to the issue explained in #88.

Sign In Path

By default, forem redirects to main_app.sign_in_path when it needs you to log in. However, every app will not necessarily have that route.

If you need to configure this to redirect elsewhere, use the sign_in_path option:

Forem.sign_in_path = main_app.some_other_route

ActionMailer Config

The mailer view templates don't have a 'request' object, so you need to specify a default host that it can use to generate the full url's for the emails. Something like this:

config.action_mailer.default_url_options = { :host => "example.com" }

Theme

For information on theming, please see the "Theming" page

User profile links

To change the username text on each post to be a link to the User's profile use the following configuration:

Forem.user_profile_links = true

Then you just need to make sure that you have routes configured for your user model to show the desired profile page. If, for example, you have a model called User then this feature expects either the user_path or user_url helper to be defined.

The simplest way you can define these in your routes is like this:

match 'users/:id', :to => "users#show", :as => :user

Alternatively, use a resources line, as it defines these helpers automatically for you:

resources :users

Avatars

By default Forem uses Gravatar for displaying avatar images for post authors. If the user object returned by forem_user responds to email, this is queried automatically. If a user does not have a Gravatar image associated with their email address they will get the default Gravatar image:

default gravatar

The behavior of the avatar image can be configured with the following configuration options.

Custom avatars

To use your own custom avatar rather than Gravatar, add the following to config/initializers/forem.rb:

Forem.avatar_user_method = 'forem_avatar'

Then ensure your User model has a forem_avatar method that returns the URL of its avatar image.

Default gravatar theme

To set a default Gravatar theme, use the .default_gravatar method:

Forem.default_gravatar = 'mm'

Default gravatar image

To set a default image, use the .default_gravatar_image method:

Forem.default_gravatar_image = 'gravatar_default.png'

When a relative path is given, it will be expanded into the absolute URL required by Gravatar with information from the request that was made and Rails's configuration. For example, given the above method call, in development this would be expanded to something like:

http://localhost:3000/images/gravatar_default.png

Passing an absolute URL to .default_gravatar_image or .default_gravatar is roughly equivalent.

More information

More information about Gravatar can be found on this page about Gravatar image requests.

Pagination

Forem supports pagination via either the will_paginate or kaminari gem. Providing you have one of these dependencies included in your Gemfile, Forem will proceed to paginate.

Forem internally uses the kaminari methods to complete the pagination, however it aliases these methods to the relevant will_paginate methods if you choose to use that gem instead. This is done automatically for you within this initializer.

To configure how many items you want per pagination page, use the Forem.per_page method as below.

Forem.per_page = 100