Search

Recent Posts

Tags


« | Main | »

Suggestions for Rails 3 Newbee

By Dale Reagan | December 11, 2011

The Joy of Rails

I wrote this list/post as I worked through Rails 3 as a newbee (not new to systems, development – just new to Rails 3.)  I am working through The Ruby on Rails 3 Tutorial and touching on issues/resolutions as I encounter them.  Note that as a Newbee my comments/solutions may not reflect ‘the Rails Way’ of doing things; also note that any solutions that I present  may or may not work for you (best I can tell this is simply part of the Joy of Rails…)  🙂

Consider some sort of Development User Sandbox

Sand-boxing development environments (isolating non-production code) is hopefully familiar/common to you.  Sand-boxing your user accounts may be less familiar but it may provide you similar isolation from ‘bad things’…

If you plan on using Online services for serving/storing data/apps etc. then here are a few items that most online tutorials don’t tell you about but they are simple things that you should consider:

While using the above approach adds some potential complexity it may help insulate you from future issues.  If you are using  a Linux/*nix type operating system then you could simply create a dedicated user for use with Open Source type projects (where you expose your information on a global scale.)  After creating the user on your local machine simply login to the account using your GUI login process.  Opening a terminal using your ‘normal’ login and then using sudo/su is possible but can lead to gotchas like:

  1. login as normal user using the GUI
  2. start a terminal session
  3. use su/sudo to change to a new user_account in the terminal session (i.e.  su – dev_user)
  4. if you now try to start a GUI process it *should* fail unless you have configured your GUI to allow direct access via a second user account (probably a very, very bad idea…)

A Sandbox Virtual Machine – A simpler approach (provided you have adequate hardware)

  1. login as normal user using the GUI
  2. create a dedicated Virtual Machine with a dedicated development user account and all development software/tools installed (with or without GUI support)
  3. start the VM and login as the dedicated development user
  4. limit ‘public projects’ to this dedicated VM

In the book Ruby on Rails Tutorial: Learn Rails by Example Michael Hartl he writes: “Also beware that lots of little things can go wrong….”, and a few sentences later on the same page, “When things like this happen to you, it’s always frustrating, but at least you know that it happens to everyone…”  [ Note that I purchased both the book and video combo product and liked them enough to become an ‘affiliate’ so clicking the link above AND purchasing help support this site – of course you could also hit the donate button…:) ]  BTW – if you are using the book/videos then you need to review the updates on the site – Chapter 13 covers Rails 3.1 and notes many of the items in this post (and possibly more.)


Rails Touts ‘Test Driven Development

Where is the Test Driven Install?

Start with a ‘clean install’

I don’t want to re-install!

  1. search engines – hoping for an ‘exact match’ WITH a solution…
  2. Rails specific forums
  3. Rails specific mailing lists
  4. your Rails ‘network’
  5. Rails books – normally at least a little out-dated within months of being published…

Common Resources for Rails Development


Ok, you create an account with Heroku, upload and successfully run a few applications and then with your next test application you hit a Heroku 500 Response code:

We’re sorry, but something went wrong.

We’ve been notified about this issue and we’ll take a look at it shortly.

This could be your code or it could be the Heroku Server.  (I noted that no one contacted me about this issue so the error message is generic and Heroku could save YOU some time by improving it…  Sounds like the price of free…)   You can query your Heroku Application logs:

>>heroku logs

2011-11-25T00:02:32+00:00 heroku[router]: GET YOUR_Application_URI.heroku.com/ dyno=web.1 queue=0 wait=0ms service=599ms status=500 bytes=728

When I experienced this I deleted the Heroku App with:

heroku rake db:migrate
rake aborted!
Please install the postgresql adapter: `gem install activerecord-postgresql-adapter` (pg is not part of the bundle. Add it to Gemfile.)
Tasks: TOP => db:migrate => db:load_config

Actually, this is a Heroku ‘confinment’Postgres is required – The Fix:

###############################
## from Heroku docs - use 'postgres' for production/sqlite for dev
group :production do
  gem 'pg'
end

group :development, :test do
  gem 'sqlite3'
end
###############################

Using ‘git’

Mr. Hartl’s book/screenscasts frequently use ‘git’ to manage the code.  If you are new to ‘git’ and if you are using his book I suggest naming ‘git commits’ with extended comments that include book chapter numbers, i.e.:

  1. rails new new_project # create a new Rails 3 project
  2. cd new_project # move into the new folder
  3. git init # initialize the folder for use with ‘git’
  4. vi Readme.markdown # create a project description file using your editor of choice (using ‘vi’ in this example)
  5. git status # git should report that there is a new file
  6. git add . # add your changes to the git repo
  7. git commit -am “Starting Chapter 1 – created project Readme” # ‘commit’ your changes with an enhanced comment
  8. git add .  # update the git repo as desired as you work through the chapter
  9. git commit -am “Chapter 1 – section on some_new_topic” # make sense?
  10. git add .  # update the git repo as desired as you work through the chapter
  11. git commit -am “Completed Chapter 1” # Completed this chapter
  12. git commit -am “Starting Chapter N “
  13. git commit -am “Completed Chapter N” # make sense?

Extended ‘commit comments’ may make it easier when reviewing the project or if you want to ‘rollback’ and re-do a section of the tutorial.   Based on my experience a reasonable approach for working through the tutorial code might be to simply ‘checkout chapters’ as you move along OR checkout the entire project and then ‘rollback’ to the point that you want to work.   During my exploration I frequently created my own issues (via fat-fingers, whoops! moments, missed ‘step #nnn”, etc.) and found that my version of the app did not work due to my new-bee-ness (well, that’s my excuse..)  Soooo, the short story for this is that I will create another post detailing using git with a ‘test project’ in this fashion.

Additional Resources


As Ruby on Rails & it’s components Transition you will most likely encounter errors like:

Warnings about deprecations – I am guessing that it is most likely you will see this from ‘generated’ code and it will continue until the ‘code generator’ is updated with the new whatever_was_deprecated OR, until the code simply no longer works and your application will (most likely) ‘break’…  It may also occur from ‘gems’ that need to be updated.

sample_app_3_1 (master)]$ rspec spec/
DEPRECATION WARNING: ActiveRecord::Associations::AssociationCollection is deprecated! Use ActiveRecord::Associations::CollectionProxy instead. (called from <top (required)> at /usr/local/Tutorial/sample_app_3_1/config/environment.rb:5)
….

Finished in 0.49615 seconds
4 examples, 0 failures

In this case I quickly found a simple solution – which I try and it appears to ‘solve’ the warning problem.  After changing the Gemfile I ran bundle install but no changes seem to occur (which probably means that the needed gem is already installed.)


StyleSheets & Images not working with Rails 3.x?

In the 3.1 release of Rails (So, for a small version change a ‘standard’ item has just bee relocated?) it appears that stylesheets should be placed in:

Check the source for the application web page – it will show you where the stylesheet is being pulled from…


Getting many errors when you try to use Annotate?  Try:

While working on the tutorial I also worked on some related posts:

 

Setting Up Local Resources – possible future posts…

As always, I expect that your experiences will vary a bit (along with your opinions) – which is as it should be.  🙂

Topics: Problem Solving, ROR, Unix-Linux-Os, Web Problem Solving, Web Technologies | Comments Off on Suggestions for Rails 3 Newbee

Comments are closed.


________________________________________________
YOUR GeoIP Data | Ip: 73.21.121.1
Continent: NA | Country Code: US | Country Name: United States
Region: | State/Region Name: | City:
(US only) Area Code: 0 | Postal code/Zip:
Latitude: 38.000000 | Longitude: -97.000000
Note - if using a mobile device your physical location may NOT be accurate...
________________________________________________

Georgia-USA.Com - Web Hosting for Business
____________________________________