I checked out from LHU library and grab this book last two days.
And I am going to take some notes here so that I can review it easily in the future, and I also would like to record a story of how n00b wrote their thoughts down.
Creating application with specific Rails version
Here is the example for Rails 4, the command:
Creating your own Rails API documentation
|
|
Alternative syntax
%{}
is an alternative syntax for double-quoted string literals, convenient for use with long strings:
And here why I used exclamation mark (!)
for create
method? The reason why is that it will raise an exception
if records cannot be inserted because of validation failed
.
Load specific stylesheet in specific controller
Deponds on controller_name
method (API)
Alternate CSS classes for even and odd numbers
Deponds on cycle
method (API)
Helpful commands for Git
If you overwrite or delete files, directries that you didn’t mean to, you can always get back by using this command:
On the contrary, if you create folders or files that you didn’t want, try:
to get back.
Handling Errors
When we enter example.com/carts/baozi
, Active Record
will raise a RecordNotFound exception. We can handle it like this:
|
|
Calculate a sum from the element (API)
|
|
So the Line_item.rb
need total_price
method: