Gems Freezing Remember that when you freeze something, it goes in your vendor directory. This is how I was able to run rails on my machine w/o installing the rails gem. However, when I went to create a new project, “rails” wasn't installed, so my machine didn't know WTF rails was. To fix this: I ran
sudo gem install -y rails
Find out what the hell the -y does
script/generate Model Recipe
script/generate scaffold Recipe
app/controllers/application.rb is the parent of all controllers. If you want a general method for all controllers, put it there.
If gems or script/generate whines with this error:
undefined method 'gem' for main:Object from 1.8/rubygems/custom_require.rb
Then try running
gem update --system
See Also
Excellent tutorial on Roll-your-own http://www.aidanf.net/rails/rails_user_authentication_tutorial
Warnings, and the filtering of the log TODO were eliminated by the tar file found here: http://www.chrissterritt.com/AidanLoginRails2.tar
Good explanation for :before_filter problem with application.rb and friends.
http://api.rubyonrails.org/classes/ActionController/Filters/ClassMethods.html
Request data is available in the params hash. The data dump of the request can be usually be seen in the /log/development.log file.
Ruby/Rails data dumps look something like this:
Parameters: {"game"=>{"event_id"=>"3", "description"=>"A one man game", "players"=>["3", "1"]}}
The rules to remember are:
The following examples show how to retrieve crap from the request:
| Code | Data “Type” | Returns the Value |
|---|---|---|
params[:result][:game][:event_id] | Hash Value | 3 |
params[:result][:game][:description] | Hash Value | “A one man game” |
params[:result][:game][:players][0] | Array Value (Note the “players”⇒[“3”, “1”] above) | “3” |
ruby Show kewl ruby data types / methods used to step through data types / collections.
script/generate model Hand
Now, edit the newly created xxx_create_hands.rb file to include the fields, etc.
To detect the version of rails you're running perform the following steps
You can see all the versions of the major components of rails by going to http://localhost:3000/rails/info/properties
Make sure you start your rails application before trying it, though :)
> script/server
You can also use the script/console program.
Go to your rails application's base directory.
> script/console
At the » prompt, type the following:
>> Rails::VERSION::STRING
You should see some output like:
=> "1.2.1"
http://forums.site5.com/showthread.php?t=20695&highlight=dispatch.fcgi
~/apps folder)rails <myapp>
ln -s ~/<railsapp>/public ~/public_html/<somequickname>
RewriteRule ^(.*)$ dispatch.cgi [QSA,L]
to
RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
~/<railsapp>/config/database.yml and put in database's name, username/password that you use to log into ssh.~/<railsapp>/config/environment.rb and change Note I'm not sure about this one.#ENV['RAILS_ENV'] ||= 'production'
to
ENV['RAILS_ENV'] = 'development'
Also, follow this link http://forums.site5.com/showthread.php?t=11954 for more junk on rails on site5. I also have this link bookmarked / cached.
The Dispatch.fcgi that comes with rails XXX has an incorrect bang! operator for Site5.
Old
#!/opt/local/bin/ruby
New
#!/opt/local/bin/ruby
I've recently found that just issuing the touch -m command on public/dispatch.fcgi will do a server restart. This is much better than the previous way of having to search for ruby dispatch.fcgi that belong to You, and killing the pids.
From the root of your rails app:
touch -m public/disptach.fcgi
See
See chapter 16.3 in AWDWR
map.connect '', :controller => "time_entries"
Best tutorial I've found so far:
http://www.aidanf.net/rails_user_authentication_tutorial
See also SaltedHash
http://wiki.rubyonrails.com/rails/pages/SaltedLoginGeneratorQuickstart
Make sure that “From” e-mail address is set up in
config/environments/user_environment.rb
Rails
* Rails will choose the layout in the app/views/layouts directory that has the same name of the controller that's handling a request that has the same name of the controller
content_for_layout variable is a “magic” one, whose content is rendered by Rails.
So if you put <%= @content_for_layout %> somewhere, then the layout will receive all the doodoo that's in the xxx.rhtml page that's using the layout.
ERb = “Embedded Ruby”
link_to_unless_current = a function in Rails that creates a link to a page, unless it's the current page! Yippee!
The link_to function uses routes.rb to figure out where to create the link to. For example,you can put in link_to :action⇒index,and rails figures out which index you're talking ab00t
Stylesheets are located in public/<controller>.css, methinks. Pge 40 RailsSpace
Start using styles immediately for your aep, and thinking about presentations and layouts, etc.
C» usr.save ⇒ false
usr.errors.on(:screen_name)
⇒ “is too short (minimum is 4 characters)”
usr.errors.on(:password)
⇒ “is too short (minimum is 4 characters)”
Ctrl-N is the auto-complete crap for vim.
use reload! to reload the environment in irb
TODO: get new \1, \2, etc from mappings.vim
Check the error logs on Site5's backdoor application. If it's whining about some permissions, change the permissions to the public folder in the app/current/public folder to 755 BEOTCH! TODO: Check the URLs above for hints about how to chmod 755 pubic erectory fodler.
Error when trying to run script/console on Edgy.
http://www.ruby-forum.com/topic/80494
solution:
sudo ln -s /usr/bin/irb1.8 /usr/bin/irb
Problem : When first setting up a database on Ubuntu Edgy, you get No such file or directory - /tmp/mysql.sock
Solution: Specify socket: /path/to/socket.sock in config/database.yml for the database you're running on Ubuntu. (Note, make sure you don't have the socket: token on production, if it's not needed.)
production:
adapter: mysql socket : /var/run/mysqld/mysqld.sock ...
Craig's Opinion on Rails Projects
| Page | Description | Tags |
|---|---|---|
| Action Mailer | The Rails Action Mailer sends e-mail using an MVC based approach. You call deliver_<something> where <something> is a method in your controller. You provide … | rails, email, smtp, actionmailer |
| Autotest | sudo gem install ZenTest <http://notesmine.com/rails_application_documentation?s=rdoc> When you run autotest, you see the results zoom by on the terminal. What… | zentest, autotest, rspec, rails |
| Capistrano | <http://wiki.dreamhost.com/index.php/Capistrano> View Avail. Tasks See what tasks are available-—including both your own custom tasks and the standard ones:… | capistrano, deployment, rails, subversion, ssh |
| Emacs Rails | I will give Emacs one more try. Vim is nice, but the windows/buffers are so annoying that I want to try Emacs. I followed the instructions on this page up to … | emacs, rails, editors, ides |
| GemRunner | You might get this error on Ubuntu, when trying to run rails after upgrading RubyGems /usr/bin/gem:23: uninitialized constant Gem::GemRunner (NameError) See <… | rails, gems, ubuntu |
| Grails Versus Rails | Get the flamethrowers out! When updating constraints, I've had to restart the Grails server. I don't seem to recall having to restart the server as much when … | grails, rails |
| RSpec Gotchas | On one of my Rails projects, I had environment.rb explicitly set ENV['RAILS_ENV'] to 'development'. In older versions of RSpec, RSpec sets the ENV['RAILS_ENV']… | gotchas, rspec, rails |
| Rails Automagic | This page is devoted to some of the obscure magical stuff that Rails does. Somehow, rails wraps the form fields that have errors with a <div> tag that has a cl… | rails, gotchas, obscurities, validation |
| Rails Documentation | A decent place to get documentation for rails is in your own project directory. From the root of your project, run rake doc:rails The files will be created i… | rails, documentation |
| Rails ERb | ERB stands for “Embedded Ruby” If you put a minus sign before the end tag (-%>), then no newline is rendered. rails, erb, rhtml, views | rails, erb, rhtml, views |
| Rails Environment | You can find out the versions of much of your Rails application by starting the server script/server Then go to this page: <http://localhost:3000/rails/info/p… | rails, environments |
| Rails Example | After working with rails for the past three months, I often find myself wasting enormous amounts of time trying to do relatively simple things in my projects. … | rails, tutorials, rails, tutorials |
| Rails Forms | See railscasts.com episode 16 about virtual attributes, which can be used to make it easier to modify two models from within the same form w/o bloating the cont… | rails |
| Rails Group | <http://stlrails.org/> <http://groups.google.com/group/stlrails?hl=en> rails, groups | rails, rails, groups |
| Rails Highlights | Bragging stuff about rails. Kind of an antithesis to rails whines. Find Or Initialize Many times, you want to create an object if none exists. Otherwise, yo… | rails, ActiveRecord |
| Rails Project Documentation | There's more than a few ways to provide documentation for your project. /doc/README_FOR_APP is a text file in all rails projects where you can put helpful poin… | rails, documentation |
| Rails Server | The Rails Way book has a chapter on setting up a Rails production server. This page is pretty much a ubuntu-specialized version of that chapter. I found anoth… | rails, mongrel, setup, server, nginx, mysql |
| Rails Sessions | Rails provides a method called ActiveRecordStore to store sessions in the database, rather than on disk, which is the default. rake db:sessions:create In conf… | rails, sessions, environment.rb |
| Rails Whines | If I create a migration, and another person creates a migration, then you could end up with the following situation: User 1 001_create_foo.rb User 2: 001_creat… | rails, rails |
| Rake | Ruby Make * Uses Ruby (not stupid XML like Ant does). Get a list of all rake tasks available. rake -T or rake --tasks Show only tasks containing spec rak… | rake, rails |
| Rspec | RSpec is an alternative to the TestUnit tool which is built into Rails. RSpec users claim these advantages over Test::Unit * Easy to read * Built for BD… | ruby, rails, rspec, ruby, rails, rspec, bdd |
| SQL Lite | A lightweight database that's good for development/test because it's fast. As far as I can tell, Xubuntu and Ubuntu are shipped with the junk that rails needs… | sqlite, rails, databases |
| Testing in Rails | Testing is a huge component of Rails, and my notes won't fit on one page. * Units - Basic tests of Models * Functional - Testing of views/controllers * I… | rails, debug, testing, rake |
| URL Helper | I put this note here to help myself gain an understanding of rails and how everything fits together. <http://api.rubyonrails.com/classes/ActionView/Helpers/Url… | rails, api, vim |
| Vim Rails | Great vim plugin for rails applications. There's an excellent Tutorial on , and I recommend you navigate through that to learn how to install and use. I liste… | todo, vim, rails, ruby, ide, todo, vim, rails, ruby, ide |
| Vim Rails Screencast | I might create a screencast showing how to use Vim w/Rails. * Show Vim setup? -- No * Show where to get Rails & related plugins? - Yes * Create Rails ap… | vim, rails, screencasts |