Rails Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

What are helpers for and where do you place them?

A

A helper is a module, as opposed to class. Helpers are a way to access methods, that a view would otherwise not have access to, and a way to keep the method code out of the view files. Helpers are placed in the /helpers folder, and must be named using the “_helper.rb” format.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are ‘concerns’ in Rails?

A

The are two concerns folders in a Rails app, one in the models folder and one in the controllers folder. The concerns folders are for bits of code that can be shared by controllers or models, thus avoiding recreating the same methods for multiple unrelated classes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do you start the rails server, and where are the web pages served:

A

Use ‘rails server’ or ‘rails s’ to start the server. The website can be found at http://localhost:3000.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do you create a basic rails app?

A

Use the ‘rails new AppName’ command. You can view the list of options by typing ‘rails new -h’ into the terminal.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the ‘rails g’ command for?

A

‘rails generate’, uses templates to generate bolierplate code for lots of different uses. Most commonly used options are ‘controller’, ‘model’, ‘scaffold’, and ‘migration’. The full list of options can be found by running the ‘rails g’ command.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How do you generate a new controller for a rails app?

A

‘rails g controller [controller name] [action1 action2 …] [options]’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How do you generate a new model for a rails app?

A

‘rails g model [modelname] [fieldname:type] [fieldname:type] …’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How are URLs structured in a Rails app?

A

http://[host}/[controller]/[action]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

When you generate a controller with the rails command, what files are created?

A

A controller file, a view file, a functional test file, a helper for the view, a JavaScript file and a stylesheet file.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How do you create a model and its controller at the same time?

A

‘rails g scaffold Name fieldname:type fieldname:type …’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How do you update the database after generating a new model?

A

run ‘rake db:migrate’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What does ‘rails console’ do?

A

Its the same as irb, it starts an interactive ruby session. Can also be called using ‘rails c’.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How can you access the database from the commandline?

A

‘rails dbconsole’ or ‘rails db’ will figures out which database you’re using and drop you into whichever command line interface you would use with it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How do you remove a model or controller from a Rails app?

A

‘rails d model [modelname]’ or ‘rails d controller [controllername]’. You can also use ‘rails destroy’ instead of ‘rails d’.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How can you get version information about the copy of Ruby, RubyGems, etc?

A

‘rake about’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are the commands to get a rails app running in 5 minutes?

A

rails new AppName
rails g scaffold Name fieldname:type fieldname:type …
update routes.rb with root ‘ControllerName#index’
rake routes
rake db:migrate

17
Q

How do you add a controller and views to a Rails app?

A

rails g controller Name method1 method2 method 3

18
Q

What is the rails server called?

A

Puma

19
Q

In the rails directory structure, what is the /bin folder for?

A

Rails scripts to setup, deploy, run, or update the app.

20
Q

In the rails directory structure, what is the /config folder for?

A

Configuration files for the routes and database.

21
Q

In the rails directory structure, what is the /lib folder for?

A

Modules to expand the app

22
Q

In the rails directory structure, what is the /public folder for?

A

The only folder seen by the world as-is. Place static files here, and compiled files.

23
Q

In the rails directory structure, what is the /tmp folder for?

A

Any temporary files like cache files.

24
Q

In the rails directory structure, what is the /vendor folder for?

A

Any 3rd party code, including the gems specified in the gemfile.

25
Q

What are the subfolders in the app folder? Hint, there are 8 of them.

A
/app/assets
/app/channels
/app/controllers
/app/helpers
/app/jobs
/app/mailers
/app/models
/app/views
26
Q

What are the main data types in rails?

A

There are 14 in total

\:binary
\:boolean
\:date
\:datetime
\:decimal
\:float
\:integer
\:bigint
\:primary_key
\:references
\:string
\:text
\:time
\:timestamp