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:
Command Line
1
$ rails _4.0.0_ new app_name
Creating your own Rails API documentation
Command Line
1
2
$ cd app_name
$ rake doc:rails
Alternative syntax
%{} is an alternative syntax for double-quoted string literals, convenient for use with long strings:
app/db/seed.rb
1
2
3
4
5
6
Product.create!(title:'Baozi', description:%{
A
n00b
of
Rails
})
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.
Recently I got a guide of telling us how to be self-taught from on-line courses. It shows me how important taking note is. I highly recommended this guide to who also wants to be self-taught.
The average person forgets 40% of what they learn within 20 minutes.
So I decide to take notes here since now. It will spend most of my time to do, but if I do not do it today, I know I won’t do it anymore. That is my lazy personality. The first technical post I am going to present my reviews of #196 Nested Model Form (revised); meanwhile, some of the codes there are not working because of the version of Rails, so I will try to make it work like video shows with the latest Rails, please revise my code if you have better ways, thanks a bunch. OK so let us get started.
Next we are going to implement removing questions feature. We will create a checkbox whose key is _destroy, so the question will be removed if checkbox is checked.
app/views/surveys/_form.html.erb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
...
...
...
<divclass="field">
<%=f.label:name %><br>
<%=f.text_field:name %>
</div>
<%=f.fields_for:questionsdo |question| %>
<fieldset>
<%=question.label:content, 'Question' %><br>
<%=question.text_area:content %><br>
<%=question.check_box:_destroy %>
<%=question.label:_destroy, 'Removequestion' %>
</fieldset>
<%end %>
Add allow_destroy option to Survey model, set the value to be true:
We get Question instance from form.object, sending association to it and call klass, we get Answer class, then call new method. Next, we fetch its object id in order to make its field.
After create fields we make a link which has data-id and data-fields attributes. So that we can retrieve fields before .add_fields.
Today is really special for me, because my Macbook Air 13" is already one year old. I remember that I felt unforgettable as soon as I touched her. I also remember that why did I think she is the one for me, do you want to know why?
Because of Ruby on Rails. I would like to learn that since I visited this blog. Those posts show me how wonderful Rails is, its porpose is to create websites, that’s what I want!
Few days later, I bought the the famous Rails developer, xdite, her book Rails 101 (It’s free now). I impressed by a part of paragraph:
Mac 是最好的 Ruby on Rails 開發環境,馬上買一台!
So I got Macbook immediatrly. I am easy to be incfuenced by someone, but I do not regret to do this. I think this pricy stuff can make money for me soon. But such a pitty, I did not try my best to learn Rails in the last year.
Now, I want to recreate my ambition. I am going to write down my thoughts of learning techniques here to train my writing skill. That’s why I spend afternoon to build this blog using Octopress, you can follow Octopress documentation to create it. If you have no idea why you must create a blog and insist on blogging, I believe Why You Should Write Daily may help you much.