Created
April 8, 2012 16:18
-
-
Save Nimster/2338235 to your computer and use it in GitHub Desktop.
Rails summary
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
COMMANDS | |
rails new demo #Create a new rails project under 'demo' | |
rails server #Start a local server to test the project, port 3000 | |
rails generate controller ControllerName action1 action2 | |
# For example 'rails generate controller say hello goodbye' gives | |
# say/hello and say/goodbye links, which are implemented by a class | |
# app/controllers/say_controller.rb with hello and goodbye methods. | |
# app/views/say/hello.html.erb will contain the template | |
rails generate scaffold ModelName fieldname:fieldtype | |
# e.g 'rails generate scaffold Product | |
# title:string description:text price:decimal' | |
# | |
rake db:migrate # When changing a file in db/migrate | |
rake test # Run the tests | |
rake db:seed # Put in the data in db/seeds.rb into the database | |
rails generate migration add_quantity_to_line_item quantity:integer #parses the | |
name to understand we are working on the line_item table | |
rails runner script.rb #Run script with your rails project context | |
rails console # Interactive ruby command line with your project context | |
rake doc:app # generate application rubydoc | |
rake routes # Show the REST routes configured | |
rake --tasks, rake --describe # learn about the tasks available | |
FILES: | |
db/seeds.rb # Starting database data, for seeing stuff | |
database.yml # database connection configuration | |
app/views/layouts/application.html.erb # headers of HTML files (for CSS | |
declarations) | |
public/stylesheets # Directory for CSS files | |
app/controllers/application_controller.rb #Base class for all controllers, so | |
#helper methods should go here | |
CODE: | |
ActiveRecord | |
validates | |
default_scope | |
has_many # for foreign keys | |
ActiveSupport::TestCase | |
fixtures | |
fixtures YML | |
in config/routes.rb you can change the root: directive to control where the | |
default (index) will go to | |
UI: | |
button_to, link_to, img_tag functions | |
controller_to_path "alias" | |
sanitize, truncate, strip_tags, pluralize functions | |
-*-*-*- | |
rails new project | |
cd project | |
rails generate scaffold Post post_name:string |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment