Bug squashing: missing footer

Tip: So…find that suddenly your header and footer for your web page don’t work on certain pages, whereas in the rest they do (i.e. a few pages don’t show it?) What may have happened is that in your app\views\layouts you deleted the layouts for most of the pages, but left a few there (note typically to add a footera nd a header you delete the layout pages for each controller, and add an “application.rthml” so what really happened is you created a controller after completing this process, i.e. you created some “after” having deleted them all).

How to change the default “opening file” in Ruby on Rails

So you delete public\index.html file,

then in
config/routes.rb
map.connect '', :controller => "welcome"

Well… that tell it to connect the default page to the welcome controller’s default action, which is the “index” action:

….app/controllers/whatever.rb
def index
list
render :action => ‘list’
end

So if you so desire and do not have a “welcome” class
then
ruby script\generate controller welcome
then create (through some means) app/views/welcome/index.rhtml and voila you have a Ruby Index page now.

Said differently
If you don’t have a controller “welcome” (already generated) then you can either list a controller that you do have, or create the “welcome” controller thus:

ruby script\generate controller welcome

now you can (if you so desire) edit controllers\welcome_controller.rb

now create make index.rhtml (possibly move public.html there) in
app\views\welcome

and done!

Creating a new rails app

So…once you get it going how do you actually make rails work?

it’s not too bad

1) start a rails project.

rails projectName

2) Setup the DB to be what you want it to be (create migrations to setup the tables).

cd projectName
rake generate migration thisIsItsName

edit configure\db.yml to use sqlite3:

development:
adapter: sqlite3
database: db/podCastBlender_development

test:
adapter: sqlite3
database: db/podCastBlender_test

production:
adapter: sqlite3
database: db/podCastBlender_production

3) run
ruby script/generate scaffold allthedatabasenames repeatthosenames
to setup some trivial database accessors/modifiers.

4) edit the models to reflect the ‘real’ relationships between the tables.
Say you have one named “users” and one named “objects” where each user has many objects?
The table for “objects” should be setup to have a field “user_id” (if user is the name of the owner)

then models\user.rb (each user has many objects, remember) is as follows:

class User < ActiveRecord::Base has_many :objects end

and objects.rb
class User < ActiveRecord::Base belongs_to :user end
[belongs_to means "I have a row that is the [primary] ID of this other entry in that table"

5) add code to use those relationships before saving the objects (like assign a user)--just a good idea generally 🙂

6) Do what you really wanted to do with the pages, etc.

How to install Ruby…

how to install ruby and get it runnin’ on windows with rails…with sqlite3
install ruby (should work) one click installer…

then
gem install rails --include-dependencies
gem install sqlite3-ruby (for windows, choose number 2:sqlite3-ruby 1.2.1 mswin32

now go to sqlite and download sqlite3 “dll without tcl bindings” and “executable” for sqlite3, copy sqlite3.exe, sqlite3.dll to ruby\bin directory
Then if the app is already developed:

run

rake migrate

now rock and roll.

If it is not ready then edit config\database.yml and change it to say something similar to:

development:
adapter: sqlite3
database: db/podCastBlender_development

# Warning: The database defined as ‘test’ will be erased and
# re-generated from your development database when you run ‘rake’.
# Do not set this db to the same as development or production.

test:
adapter: sqlite3
database: db/podCastBlender_test

production:
adapter: sqlite3
database: db/podCastBlender_production
And you are done!

Roger's meanderings, notes to himself, bug reports, and other things