Topic: Where do custom config data live?

Hi All,

So, I've totally disregarded the helpful, friendly advice from ryanb & am pressing on with writing my own Ruby code to integrate my Rails app (running the Login Engine) with phpBB.  Ryan may pout, but I'm sure the cartoon foxes would approve :-)

To my pleasant surprise, it's working nicely. I've modified user_control.rb to modify the phpBB session table on login and logout, and mimic the cookie writing behaviour in phpBB's session.php code.  I can log in to my Rails app, navigate to my forum index and I'm logged in there too.  Nice.  And when I log out from my Rails app, the cookies are overwritten and the session table cleaned up.  Also nice.

However, I'm currently using hardcoded strings for the phpBB settings I need to know:

# TODO: get these from a configuration file?
cookie_path = '/'
cookie_domain = ''
cookie_secure = false
phpbb_db_name = "phpbb"
phpbb_db_username = "mydbusername"
phpbb_db_password = "mydbpassword"
phpbb_db_hostname = "localhost"

I'm sure there must be some Rails-ish way of putting those settings in a configuration file somewhere, where they can be cleanly accessed.  I've had a hunt around the documentation & forum, but can't find a best practice for this.

Anyone have any suggestions?

Yours,
Duncan Bayne

Re: Where do custom config data live?

*pouts*

That's okay, glad it's working! I'm honestly surprised it worked so well.

Anyway, configurations are usually placed in config/environment.rb file. However, simple variables won't work here because the objects don't have access to them. I'm assuming these values won't be changing, so constants will proably work well. To do that, make them all caps. You can then access them from anywhere:

COOKE_PATH = '/'
COOKIE_DOMAIN = ''
#...

Tip: if you look in the config/environments folder you will see a file for each kind of environment. You can place configs in here instead if you need them to change depending upon what environment Rails is running in.

Railscasts - Free Ruby on Rails Screencasts

Re: Where do custom config data live?

ryanb wrote:

*pouts*

That's okay, glad it's working! I'm honestly surprised it worked so well.

Thanks :-)  I'll speak to my clients & see if they're happy with me releasing the code, & if so, post it here ... that said it's not terribly difficult, just requires a bit of PHP nous to work out the significant parts of session.php, & replicate the functionality in Ruby. 

Actually, after rooting through the phpBB code, I have newfound respect for the aesthetics of Ruby on Rails :-)

ryanb wrote:

Anyway, configurations are usually placed in config/environment.rb file. However, simple variables won't work here because the objects don't have access to them. I'm assuming these values won't be changing, so constants will proably work well. To do that, make them all caps. You can then access them from anywhere:

COOKE_PATH = '/'
COOKIE_DOMAIN = ''
#...

Tip: if you look in the config/environments folder you will see a file for each kind of environment. You can place configs in here instead if you need them to change depending upon what environment Rails is running in.

Thanks, that sounds ideal.

You know, I'm coming to RoR from a background in C# and to a lesser extent, PHP and am very impressed.  I took my current contract under conditions of urgency (five weeks to develop the site from scratch to beta release) & was a bit stressed at the time ... but the more I use RoR, the happier I am with it :-)

Re: Where do custom config data live?

duncan_bayne wrote:

You know, I'm coming to RoR from a background in C# and to a lesser extent, PHP and am very impressed.  I took my current contract under conditions of urgency (five weeks to develop the site from scratch to beta release) & was a bit stressed at the time ... but the more I use RoR, the happier I am with it :-)

Ruby and RoR have been quite the epiphany for me. I'd almost go so far as to say there are two kinds of developers out there now: those who've experienced RoR and those who haven't. A coworker of mine was interested in RoR and so I was telling him about it and showing him some of my code, and he was impressed and intrigued. This other guy overheard us and basically said "I'll just stick to php thanks", and I didn't even bother to convince him or anything, it's just one of those things you have to experience for yourself.

C# development pays my bills, but I can say for sure that my RoR hobby has made me a better developer across the board.

Re: Where do custom config data live?

In an idle moment at work (my day job, coding in C#) I was wondering whether a Rails-like framework could be designed for Windows devleopment, where WPF via. XAML was used for the UI (instead of HTML), C# for the language (instead of Ruby), and the framework implemented in Windows PowerShell.

That'd be an interesting project all right.