FeaturesPluginsDocs & SupportCommunityPartners

NetBeans Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  

Need help with Ruby code in doc example about setting env variable

 
Post new topic   Reply to topic    NetBeans Forums -> Ruby Users
View previous topic :: View next topic  
Author Message
Chris Kutler
Posted via mailing list.





PostPosted: Fri Oct 17, 2008 4:44 pm    Post subject: Need help with Ruby code in doc example about setting env variable Reply with quote

Hello,

I am adding a blurb in 6.5 docs about setting the environment for
running on GlassFish. The Rails Environment setting in the Project
Properties dialog box does not affect running the app on GlassFish (on
for WEBrick and Mongrel). Instead you need to set the environment in
your environment.rb file.

In my testing, I have done this

RAILS_ENV = 'test'

I notice that the comments in the file say to do this:

ENV['RAILS_ENV'] ||= 'test'

Should that be how I document it?

I don't understand the ||= part.

I know that || means or. I am guessing that ||= means:

If ENV['RAILS_ENV'] has a value use that, otherwise set it to 'test' ????

I also notice this code:

RAILS_GEM_VERSION = '2.1.1' unless defined? RAILS_GEM_VERSION

So, why isn't that

ENV['RAILS_GEM_VERSION'] ||= '2.1.1'

I feel that I am not understanding the usage of ENV[] and environment
variables.
Back to top
bruparel
Posted via mailing list.





PostPosted: Fri Oct 17, 2008 6:53 pm    Post subject: Need help with Ruby code in doc example about setting env variable Reply with quote

Hello Chris,
I do not have all the answers but will try to address as many as I can.
Here we go:

You wrote:

"I notice that the comments in the file say to do this:

ENV['RAILS_ENV'] ||= 'test'

Should that be how I document it?

I don't understand the ||= part.

I know that || means or. I am guessing that ||= means:

If ENV['RAILS_ENV'] has a value use that, otherwise set it to 'test' ????"

-- Quite correct. This is how ruby shortens code.

You wrote:

"I also notice this code:

RAILS_GEM_VERSION = '2.1.1' unless defined? RAILS_GEM_VERSION

So, why isn't that

ENV['RAILS_GEM_VERSION'] ||= '2.1.1'"

-- The reason for doing that is RAILS_GEM_VERSION constant can be defined
elsewhere. In particular, if you "freeze" a specific version of Rails in
the vendors directory then that particular version overrides the currently
installed Rails version using "gem intall command" in your current
environment. Freezing a specific version of Rails in the vendor directory
is a common practice (or shall we say a best practice?) to ensure that your
application runs against the same version of Rails in ANY environment that
you deploy.

You wrote:
"I feel that I am not understanding the usage of ENV[] and environment
variables."

If you go through Obie Fernandez's excellent "The Rails Way" text, he
explains all this in detail in the very first chapter of his book. As you
move beyond the introductory materials in Rails, Obie's book becomes very
useful.

Hope this helps.

Regards,

Bharat

--
View this message in context: http://www.nabble.com/Need-help-with-Ruby-code-in-doc-example-about-setting-env-variable-tp20036947p20039073.html
Sent from the NetBeans Ruby Users mailing list archive at Nabble.com.
Back to top
Chris Kutler
Posted via mailing list.





PostPosted: Fri Oct 17, 2008 8:21 pm    Post subject: Need help with Ruby code in doc example about setting env variable Reply with quote

In other words,

I should use the following code example to show how to set RAILS_ENV in
the environment.rb file

ENV['RAILS_ENV'] ||= 'test'

Thanks for the pointer to the book. I was able to look at Chapter 1 and
it does provide some helpful information.
Back to top
(((Bonsai Studio))) - Giu
Posted via mailing list.





PostPosted: Fri Oct 17, 2008 8:52 pm    Post subject: Need help with Ruby code in doc example about setting env variable Reply with quote

Which book?

Il giorno 17/ott/08, alle ore 22:21, Chris Kutler ha scritto:

Quote:
In other words,

I should use the following code example to show how to set RAILS_ENV
in the environment.rb file

ENV['RAILS_ENV'] ||= 'test'

Thanks for the pointer to the book. I was able to look at Chapter 1
and it does provide some helpful information.






Back to top
Chris Kutler
Posted via mailing list.





PostPosted: Fri Oct 17, 2008 8:56 pm    Post subject: Need help with Ruby code in doc example about setting env variable Reply with quote

Earlier in the thread, Bharat wrote

Quote:
If you go through Obie Fernandez's excellent "The Rails Way" text, he
explains all this in detail in the very first chapter of his book. As you
move beyond the introductory materials in Rails, Obie's book becomes very
useful.


(((Bonsai Studio))) - Giuseppe wrote:
Quote:
Which book?

Il giorno 17/ott/08, alle ore 22:21, Chris Kutler ha scritto:

Quote:
In other words,

I should use the following code example to show how to set RAILS_ENV
in the environment.rb file

ENV['RAILS_ENV'] ||= 'test'

Thanks for the pointer to the book. I was able to look at Chapter 1
and it does provide some helpful information.












Back to top
(((Bonsai Studio))) - Giu
Posted via mailing list.





PostPosted: Fri Oct 17, 2008 9:07 pm    Post subject: Need help with Ruby code in doc example about setting env variable Reply with quote

Thanks Chris, didn't get it.

Il giorno 17/ott/08, alle ore 22:56, Chris Kutler ha scritto:

Quote:
Earlier in the thread, Bharat wrote

Quote:
If you go through Obie Fernandez's excellent "The Rails Way" text, he
explains all this in detail in the very first chapter of his book.
As you
move beyond the introductory materials in Rails, Obie's book
becomes very
useful.


(((Bonsai Studio))) - Giuseppe wrote:
Quote:
Which book?

Il giorno 17/ott/08, alle ore 22:21, Chris Kutler ha scritto:

Quote:
In other words,

I should use the following code example to show how to set
RAILS_ENV in the environment.rb file

ENV['RAILS_ENV'] ||= 'test'

Thanks for the pointer to the book. I was able to look at Chapter
1 and it does provide some helpful information.


















Back to top
Display posts from previous:   
Post new topic   Reply to topic    NetBeans Forums -> Ruby Users All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB