2021 ROR Flashcards

1
Q

What is a scope in ROR?

A

Scopes are custom queries that you define inside your Rails models with the scope method.

in Post model:
scope :free, -> {where(premium: false)}

In Post controller:
@posts = Post.free

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

Why use scopes in ROR?

A

Scopes helps you avoid errors when your scope returns nothing.

<div>

</div>

<pre>
<code>
Scopes are used for exactly one thing, <br></br>
so you know what you get the moment you see one
</code></pre>

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

What does the error “Uninitialized Constant” mean?

A

It probably means that there is a file missing

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

What are the naming conventions for controllers?

A

The naming convention for controllers is Plural
example
EventsController, BookingsController etc

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

How do you add a favicon to an rails app?

A

in layout.html.erb and inside the head tag add:

And the image in the assets/images folder

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