It was also my problem to not to be able to continue with old tutorials to make nice scaffold thing, so i searched and found the solution and they say this method is nicer than earlier one. Actually since i dont know the earlier version it doesn’t matter for me, but i share here how i could proceed with scaffold… here you are.
rails -d mysql my_inventions mysqladmin -u root --password=my_pass create my_inventions_development cd my_inventions mate .
Till here it was just creating the project and database and creation of database table will follow. In code above in the last row we opened our project folder with TextMate to edit some code. You may edit with whatever you want as you know. let’s continue:
don’t forget to type your mysql user credentials to your config/database.yml file.
development: adapter: mysql encoding: utf8 database: my_inventions_development username: root password: my_pass socket: /tmp/mysql.sock
and let’s go to scaffold part,
script/generate scaffold invention title:string description:text instructions:text
so we created necessary files for my inventions. but it is better to edit ActiveRecord migration file to create better, tidier db table. So, open the file under db/migrate/ there should be one file since we scaffolded only once. I changed it as below, by just adding limits.
class CreateInventions < ActiveRecord::Migration
def self.up
create_table :inventions do |t|
t.string :title, :limit => 100
t.text :description, :limit => 255
t.text :instructions
t.references :category
t.timestamps
end
end
def self.down
drop_table :inventions
end
end
after we do this lets shape our db, with performing a rake db:migrate
rake db:migrate
now the table is created.
run the server by:
script/server -p 3001
by typing -p 3001 you run the web server on port 3001, you dont need to do that but it is good to know how to do that. Now open a browser and type localhost:3001 and check if it works.
I hope that works:)
IMPORTANT UPDATE
< > these characters are not shown in snippets i showed because of wp-syntax plugin of this wordpress blog, sorry for that. Please exchange
< with <
and
> with >
these signs…
Tutorial is written with no warranty, if you burn your processor, or if you get failures warnings etc and by rage if you break your monitor, it is your own risk, none the less if such damage occurs believe me it’s not because of me…