download macports
download xcode
update ruby
sudo gem update –system
(sudo gem install rubygems-update
sudo update_rubygems)
for updating all gems: sudo gem update
Can’t find header files for Ruby
If you get the can’t find header files for ruby error message when trying to build an extension or a gem, it means that Ruby cannot locate its header files.
Header files are not delivered by default with Mac OS X, you need to install the Xcode Tools package after the installation. You can find it in the Optional Installs / Xcode Tools directory on the Leopard DVD.
ERROR: Failed to build gem native extension.
Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers. Check the mkmf.log file for more details. You may need configuration options.
Answer: In this case, I did not have mysql installed while I have been attempting to do sudo gem install msyql.
And in this case, you download it from the mysql homepage .
After trying to open scripts/mysql_install_db, received this error:
FATAL ERROR: Could not find ./bin/my_print_defaults
Answer: I installed the tar package instead of the dmg package. The dmg package will automatically install the program onto your computer whereas with the tar package has to be manually installed, which either makes you more geeky or in my case, makes things a bitch.
Go back to the mysql page and download the appropriate dmg package. x86 means how fast your processor is (can wiki x86.) And dmg on this page is called the ‘package format’ downloads. Click download (in my case, I downloaded the x86 version). When it’s done installing, double click on both of the .pkg apps as well as the .prefPane app (will install mysql into your prefs panel).
Mysql is a bit odd and locates itself into /usr/local/mysql/bin/mysql rather than /usr/local/mysql. The mysql at the end of this command is the same as saying /usr/local/mysql/bin/mysql, whereas mysql can be both a noun and a verb. I myself would prefer it if mysql were always a noun ie you would say instead run mysql or irb mysql and that’s that.
Sudo mkdir a /usr/local/bin (in my case, I didn’t have bin)
and then
sudo ln -s /usr/local/mysql/bin/mysql /usr/local/bin/mysql
ln -s will make a link for you. It’s like a redirect or a post it note that says that what you were looking for is instead in this other folder.
You can echo $PATH afterwards and will give you:
/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
Then to test to see if mysql is working, type in
c-cs-macbook:~ cc$ mysql
and it should be up and running.
If this works, then rails should run perfectly and we are all set.
To check your mysql version, type “mysql –version”. mysql -v somehow doesn’t read and will instead start up mysql in your terminal.
FTP == file transfer protocol
HTTP == hypertext transfer protocol
—
Type in:
cristina-ibook:~cristina$ rails -d mysql tutorial
computer name (already set) + rails -d mysql + document name
or
cristina-ibook:~cristina$ rails tutorial
computer name (already set) + rails + document name
# in this case, the default database engine will be sqlite3
*Enter*
The terminal will run ‘tutorial’ and will tell you what documents it created for your program
cristina-ibook~cristina$: cd tutorial
# cd means ‘change directory’. You need to switch to the ‘tutorial’ directory in order to modify anything
# if you cd into the wrong directory or you want to work on a different project you can type ‘cd ..’ and it will go up
# one directory. If you just write cd, it will take you to your home directory
*Enter*
When you switch into ‘tutorial’, it will specify it’s new document name along with your computer’s name
crisitna-ibook:~/tutorial cristina$ rake db:create
# this is a much faster way to create your database (You do not need to go into #cocoamysql, ruby will create it for # you). If you are using sqlite, it automatically makes a database for you
cristina-ibook:~/tutorial cristina$ ./script/generate scaffold post title:string body:text
# ‘.’ tells you that you want to something in this specific document
# ruby automatically makes the created_at and updated_at for you (it will be called timestamps in the editor)
# ‘script’ is a small program that does something
# generate will make create your document
# scaffold is the basic default pre-made structure that rails provides for you for your document
# post and body are the variables/subdocuments you want to create. You can name this anything. Title and text
# are the conditions that these variables take. There are set conditions and you can’t make these up. You can look # these up. The ‘:’ tells the computer that the word following title is a characteristic of title and will create that, in
# this case, as a string
# any two+ worded commands take an underscore or it will think that ‘scaffold resource’ are two different
# commands and won’t understand your code or will run each command separately
# you needn’t put in id:integer because the document automatically makes an id for it
# you do not want to call the subdocument in its plural form or you will create problems for yourself later
cristina-ibook:~/tutorial cristina$ ./script/generate scaffold comment title:string body:text post_id:integer
# a comment belongs to a post so it has a post id
cristina-ibook:~/tutorial cristina$ rake db:migrate
# db stands for database
# migrating the database means that any new code that is to be implemented into the database will be ‘migrated’
# over and the newest variables will be updated to the system
./script/server
0.0.0.0/posts
localhost:3000/posts
# 0.0.0.0 is the ip address if you are on the computer that is running off the code; you can double check the ip
# address for your tutorial in your terminal. Same for localhost. The default ip address is 3000. If you have
# something running on your localhost, you can set the next app on another port by declaring -p 300_ i.e. 3002
# posts is the path that you want to get to
post.rb
has_many :comments;
validates_presence_of :title, :body;
# any characteristic that follows each trait takes the ‘:’ . Remember to keep the ‘:’ right next to the trait or the
# computer won’t read it properly
comment.rb
belongs_to :post
validates_presence_of :title, :body;
copy ‘index’ of comment and include in ‘show’ of post
./script/generate migration
you can use the ‘tab’ button to help complete your sentence
ex. if you type in
cristina-ibook:~tutorial cristina$ cd tut
and then hit tab, the computer will automatically search through its database and look for document titles that start with tut
in this case, there is only one document beginning with ‘tut’ so the computer reads back
cristina-ibook:~tutorial cristina$ cd tutorial
render text
using emacs as an editor
ctrl x s => will save the document for you
ctrl x f => will pull out the ‘find document’ on the bottom of emacs and you can proceed to type in what you are looking for
ctrl g => kills whatever code you were typing in the bottom
ctrl k => kills off the line that you are on
finding your computer’s ip address:
/sbin/ifconfig
in a terminal
then look for a line that says:
inet addr:
it’ll look like this:
inet addr: 10.200.2.177
that’s my local one.
rake db:create =>
rake db:migrate
./script/destroy scaffold carpools
you are telling the scaffold that you want to destroy the carpools
rm -rf text/fixtures
rails -v
it will tell you the current rails version you are using
rake db:migrate VERSION=0
when you want to delete something in a directory such as: ~/projects/sunshine/harmony
/app/views/ride_posts, you want to use rm -rf
tail -f log/development.log
tails whatever you are doing
emacs: if emacs is locked-press p (seems to work on a temporary basis)
svn up/update
screen.css => mix code
screen.css.mine => my code
screen. css.r0945 => r means revision and the number is what number revision
a C in svn means conflict
svn resolved public/stylesheets/boilerplate.screen.css
svn resolved ______ (need to put in app file that you fixed)
svn st/stats
.find (:all,
rder => ‘id DESC’)
can either do ./script/console which works with ruby + rails + all the apps from that file or can use irb which is only ruby
if calling a new variable in the console, you need to make sure you have that variable already in the model (ex. i want to write person = Person.new and I don’t have person in my current project, then i will need to make a new tab in the model folder and create person.rb)
On Wed, May 7, 2008 at 3:50 PM, C C wrote:
writing comments for:
rails => #
css => /* */
./script/generate scaffold page title:string body:text parent_id:integer
the kids are holding onto the parents and therefore they need to know their parent’s id (it would be harder for the parents to remember how many and who are their kids)
rake db:drop
if you are using the same rails db name and you need to get rid of the information that is currently there, rake db:drop will drop the db and then you do rake db:create and you will be all set (if you do not do rake db:drop, you will get an error that says (Mysql::Error: Table ‘adventure_development.pages’ doesn’t exist: SELECT * FROM `pages`)
in the console
x = [1,2,3,4]
=> [1,2,3,4]
x.each do |y|
puts y
end
1
2
3
4
=> [1,2,3,4]
if you want to increment the result, you need to use map because each can increment the output but will not change the array and only returns the original sequence; if you want to return a different array then you use map
x.map do |y|
y + 2
end
=> [3,4,5,6]
in terminal, if you write
drscheme &
the & means start whatever program but let it keep running in the background and the terminal keep taking the input
(in the controller)
whenever you are redirecting someone to a url, it has to start with a slash; therefore, if you name it “unauthorized” it needs to be redirected to “/unauthorized” for it to work (also, if you don’t add anything to unauthorized, the page thinks that it is a html page by default and so you should name the emacs page that you want to change the information in: unauthorized.html)
(you don’t want it to be html because you can’t write the proper code so make it rhtml)
cristina@cristina-laptop:~/adventure$ mv public/unauthorized.html app/views/pages/unauthorized.rhtml
don’t need a to to move set file to new file
/config/routes
map.root => means 0.0.0.0:3000/
On Jan 25, 2008 4:09 PM, C C wrote:
Ruby 2.0.2
Start the terminal/iterm
Type in:
cristina-ibook:~cristina$ rails -d mysql tutorial
computer name (already set) + rails -d mysql + document name
*Enter*
The terminal will run ‘tutorial’ and will tell you what documents it created for your program
cristina-ibook~cristina$: cd tutorial
cd means ‘change directory’ and you need to switch to the ‘tutorial’ directory in order to modify anything
if you cd into the wrong directory or you want to work on a different project you can type cd ..
*Enter*
When you switch into ‘tutorial’, it will specify it’s new document name along with your computer’s name
crisitna-ibook:~/tutorial cristina$ rake db:create
this is a much faster way to create your database (you do not need to go into cocoamysql, ruby will create it for you)
cristina-ibook:~/tutorial cristina$ ./script/generate scaffold post title:string body:text enter
. tells you that you want to run something in this specific document
*now ruby automatically makes the created_at and updated_at for you (it will be called timestamps in the editor)
script is a small program that does something
generate will make something
scaffold_resource creates a pre-made structure for your document
any two+ worded commands take an underscore or it will think that ‘scaffold resource’ are two different commands and won’t understand your code or will run each command separately
post is the name of the subdocument you want to create, next you need to list the characteristics of ‘post’ (title, body, created_at)
the : tells the computer that the word following title is a characteristic of title and will create that, in this case, as a string
you needn’t put in id:integer because the document automatically makes an id for it
note: you do not want to call the subdocument in its plural form or you will create problems for yourself later
cristina-ibook:~/tutorial cristina$ ./script/generate scaffold comment title:string body:text post_id:integer
a comment belongs to a post so it has a post id
cristina-ibook:~/tutorial cristina$ rake db:migrate
db stands for database
migrating the database means that any new code that is to be implemented into the database will be ‘migrated’
./script/server
0.0.0.0/posts
0.0.0.0 is the ip address if you are on the computer that is running off the code; you can double check the ip address for your tutorial in your terminal
posts is the path
textmate=> models=>
post.rb
has_many :comments;
validates_presence_of :title, :body;
any characteristic that follows each trait takes the :
comment.rb
belongs_to :post
validates_presence_of :title, :body;
copy ‘index’ of comment and include in ‘show’ of post
./script/generate migration
you can use the ‘tab’ button to help complete your sentence
ex. if you type in
cristina-ibook:~tutorial cristina$ cd tut
and then hit tab, the computer will automatically search through its database and look for document titles that start with tut
in this case, there is only one document beginning with ‘tut’ so the computer reads back
cristina-ibook:~tutorial cristina$ cd tutorial
render text
using emacs as an editor
ctrl x s => will save the document for you
ctrl x f => will pull out the ‘find document’ on the bottom of emacs and you can proceed to type in what you are looking for
ctrl g => kills whatever code you were typing in the bottom
ctrl k => kills off the line that you are on
finding your computer’s ip address:
/sbin/ifconfig
in a terminal
then look for a line that says:
inet addr:
it’ll look like this:
inet addr: 10.200.2.177
that’s my local one.
rake db:create =>
rake db:migrate
./script/destroy scaffold carpools
you are telling the scaffold that you want to destroy the carpools
rm -rf text/fixtures
rails -v
it will tell you the current rails version you are using
rake db:migrate VERSION=0
when you want to delete something in a directory such as: ~/projects/sunshine/harmony/app/views/ride_posts, you want to use rm -rf
tail -f log/development.log
tails whatever you are doing
emacs: if emacs is locked-press p (seems to work on a temporary basis)
svn up/update
screen.css => mix code
screen.css.mine => my code
screen. css.r0945 => r means revision and the number is what number revision
a C in svn means conflict
svn resolved public/stylesheets/boilerplate.screen.css
svn resolved ______ (need to put in app file that you fixed)
svn st/stats
.find (:all,
rder => ‘id DESC’)
can either do ./script/console which works with ruby + rails + all the apps from that file or can use irb which is only ruby
if calling a new variable in the console, you need to make sure you have that variable already in the model (ex. i want to write person = Person.new and I don’t have person in my current project, then i will need to make a new tab in the model folder and create person.rb)
writing comments for:
rails => #
css => /* */
./script/generate scaffold page title:string body:text parent_id:integer
the kids are holding onto the parents and therefore they need to know their parent’s id (it would be harder for the parents to remember how many and who are their kids)
rake db:drop
if you are using the same rails db name and you need to get rid of the information that is currently there, rake db:drop will drop the db and then you do rake db:create and you will be all set (if you do not do rake db:drop, you will get an error that says (Mysql::Error: Table ‘adventure_development.pages’ doesn’t exist: SELECT * FROM `pages`)
in the console
x = [1,2,3,4]
=> [1,2,3,4]
x.each do |y|
puts y
end
1
2
3
4
=> [1,2,3,4]
if you want to increment the result, you need to use map because each can increment the output but will not change the array and only returns the original sequence; if you want to return a different array then you use map
x.map do |y|
y + 2
end
=> [3,4,5,6]
in terminal, if you write
drscheme &
the & means start whatever program but let it keep running in the background and the terminal keep taking the input
(in the controller)
whenever you are redirecting someone to a url, it has to start with a slash; therefore, if you name it “unauthorized” it needs to be redirected to “/unauthorized” for it to work (also, if you don’t add anything to unauthorized, the page thinks that it is a html page by default and so you should name the emacs page that you want to change the information in: unauthorized.html)
(you don’t want it to be html because you can’t write the proper code so make it rhtml)
cristina@cristina-laptop:~/adventure$ mv public/unauthorized.html app/views/pages/unauthorized
.rhtml
don’t need a to to move set file to new file
/config/routes
map.root => means 0.0.0.0:3000/
Reply
Forward
C C
show details Feb 13
Reply
if you’re doing posts/1/comments, when you’re doing the scaffold, comments must have post_id:integer
It would be pretty hot if it were ./script/scaffold rather than ./script/generate scaffold.
On rendering partials:
_posts.html.erb = save under a folder. This document will only affect local files e.g. if _posts.html.erb is saved under /app/views/posts, then /posts/index.html.erb and such files can be affected. Files under /app/views/admin/posts will not be affected by _posts.html.erb since it’s in a different folder.
@posts %>
so when placing the code that you want in _posts.html.erb, it reads so that line can be deleted in the index.html.erb or wherever.
this reads like a collection so it’s like there is an array of posts and any posts that carry render partial will be affected.
or
post %>
you can only use this when there is already an @posts %> somewhere. post %> reads like the individual post that is in the array collection.
And everything works exactly the same way as if the code was still in the view (It’s just pulling from somewhere else.)
rake routes – to see what your current routes are, just remember to be in set project and not the home screen
if you’re going to cp, you need to use -r or the terminal will complain:
cp -r ../../projects/blog .
Best pages to help you when installing restful auth:
installation process
config routes
map.activate ‘/activate/:activation_code’, :controller => ‘users’, :action => ‘activate’, :activation_code => nil
map.signup ‘/signup’, :controller => ‘users’, :action => ‘new’
map.login ‘/login’, :controller => ‘sessions’, :action => ‘new’
map.logout ‘/logout’, :controller => ‘sessions’, :action => ‘destroy’
rake db:migrate VERSION=____
undefined local variable or method
If you’re trying to cp something and it gives you the “___ is a directory (not copied)”, then use
If you want to make lists and move items up and down easily with arrows, you can download acts_as_list . Here’s a reference sheet .
###
gem list
gem help
if you want to remove a directory, you need to do:
rm -rf
if not, you can just do
rm
Check out Evernote: http://www.evernote.com/
Cool, thanks for the heads up! I’ve heard of them before.