Rails Flashcards
Where are links managed in rails?
routes.rb
Where is the Rails API found?
api.rubyonrails.org
How do you get started with rails?
gem install rails;rails new myapp;cd myapp;rails server
Template files where ruby and html code co-exist?
.erb files
How do you display an image link?
0), :action => ‘about’ %>
Where are gems needed for a web application listed?
Gemfile
How do you install all gems listed in Gemfile?
bundle install
How do you start the server? What port will it listen on by default?
rails server; runs on port 3000 by default
How do you get started with (install) heroku?
gem install heroku
How do you upload your SSH pulic key to heroku?
heroku keys:add
How do you setup your heroku remote applicatino?
heroku create
How do you push your master branch to heroku remote?
git push heroku master
How do you renamge your heroku app
giving it a new [name].heroku.com?,heroku rename superName
What does ReST stand for?
Representational State Transfer
How do you get rails to automatically generate User with id, name, email?
rails generate scaffold User name:string email:string
How do you create a class “Task” that extends from ActiveRecord?
class Task < ActiveRecord::Base
How do you get all the names as an array?
find(:all).collect(&:name)
How do you prevent an attribute (admin) from being set via mass assignment?
attr_protected :admin
app/
Core application (app) code, including models, views, controllers, and helpers
app/assets
Applications assets such as cascading style sheets (CSS), JavaScript files, and images
bin/
Binary executable files
config/
Application configuration
db/
Database files
doc/
Documentation for the application
lib/
Library modules
lib/assets
Library assets such as cascading style sheets (CSS), JavaScript files, and images
log/
Application log files
public/
Data accessible to the public (e.g., web browsers), such as error pages
bin/rails
A program for generating code, opening console sessions, or starting a local server
test/
Application tests (made obsolete by the spec/ directory in Section 3.1)
tmp/
Temporary files
vendor/
Third-party code such as plugins and gems
vendor/assets
Third-party assets such as cascading style sheets (CSS), JavaScript files, and images
README.rdoc
A brief description of the application
Rakefile
Utility tasks available via the rake command
Gemfile
Gem requirements for this app
Gemfile.lock
A list of gems used to ensure that all copies of the app use the same gem versions
config.ru
A configuration file for Rack middleware
.gitignore
Patterns for files that should be ignored by Git
Start a rails server
> rails s
app/assets/
CSS and Javascript files for the app
app/controllers/
All the controllers that handle requests fro the app
app/helpers/
Helper methods for the views in the browser
app/mailer/
All the modules to send email from the app
app/models/
The models that interact the database; ActiveRecord::Base selector classes
app/views/
HTML templates for the app
Create a controller
> rails g controller CONTROLLER_NAME [methods]
Kill a rails server
Ctrl + C
Crete a database model
> rails g model TABLE_NAME [field:data_type] Models are the database tables for storing and structuring data
Ruby make command
> rake (rails make)
Create the database table from a model
> rake db:migrate
A variable
@variable_name
A hyperlink
Set a variable equal to all rows in a table
@variable = Table.all
See routes available in the system
> rake routes
Render with no body
head status: 503
Redirect method
redirect_to PAGE_URL
Render a template into a layout
looks for a template with the same name as the request
Layout tag for CSS
“all” %>
Layout tag for Javascript
Layout tag for meta data
Include a textbox within a form
Include a checkbox within a form
Include a date selector within a form
Include a submit button
Loop through all the items in a database table
@variable.each
To get input from the console
variable = gets
To print something to the console
puts “PRINTED”