Forum: Ruby on Rails Please explain me this ruby code...

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
8c70506408fddb9740b4de7339055c77?d=identicon&s=25 Prashant Tiwari (tiwaripk)
on 2006-05-04 14:50
Hi all,
This is small code from typo 2.6.0's "articles_helper.rb" file
================================
  def author_link(article)
    if config['link_to_author'] and article.user and
article.user.email.to_s.size>0
      "<a
href=\"mailto:#{article.user.email}\">#{article.user.name}</a>"
    elsif article.user and article.user.name.to_s.size>0
      article.user.name
    else
      article.author
    end
  end
================================

In above code What is the meaning of "config['link_to_author']"????
What is "config" here??
Please tell me.

Thanx in advance.
Prash
Bc80625db60e9db4394c51d6c1892b49?d=identicon&s=25 Derrick Spell (Guest)
on 2006-05-04 15:14
(Received via mailing list)
> In above code What is the meaning of "config['link_to_author']"????
> What is "config" here??
> Please tell me.

Well, it looks like a hash name config.  I've never used Typo, but I
would venture to guess that it allows you to set some preferences
which get stored in a hash named config.

-Derrick Spell
455ac2a64d06dc8461f4d258d7f7e980?d=identicon&s=25 Michael Trier (Guest)
on 2006-05-04 15:17
(Received via mailing list)
Yeah, basically it's looking up a configuration setting in the admin
section that says, "does this user want to allow a link to their
email."  If the setting is set, then the anchor html is written out
otherwise the just the author's name is written out.

Michael
13ea48f056b19349027d2f4a6921a46a?d=identicon&s=25 Jean-François (Guest)
on 2006-05-04 15:39
(Received via mailing list)
Hello Prashant,

> This is small code from typo 2.6.0's "articles_helper.rb" file
> ================================
>   def author_link(article)
>     if config['link_to_author'] and article.user and
> article.user.email.to_s.size>0
[...]
> ================================
>
> In above code What is the meaning of "config['link_to_author']"????
> What is "config" here??

config is a method that returns the value of the global variable
$config.
(it hides implementation, just like params() gives access to @params)
$config holds an Configuration instance. The Configuration class derives
from ConfigManager class that defines a [] method. So $config inherits
a [] method and can be seen as a hash-like object (not really, because
[]= method is not implemented). config[key] is a way to access
to default settings (by default config['link_to_author'] is false).

All details are in app/models/configuration.rb and
app/models/config_manager.rb

    -- Jean-François.
This topic is locked and can not be replied to.