Skip to main content

Learning Ruby on Rails

 1. Polymorphic Association
http://railscasts.com/episodes/154-polymorphic-association
http://guides.rubyonrails.org/association_basics.html#polymorphic-associations

For instance, a book can be liked and a video can also be liked. To make a generalised association which can like both a book an a video, we can simply make a polymorphic association named likeable which contains the likable_type and likable_id. 

2.  Choose between has_many :through and has_and_belongs_to_many
http://guides.rubyonrails.org/association_basics.html#choosing-between-has-many-through-and-has-and-belongs-to-many

For instance, a book has many tags and a tag can be associated with many books. To make a simple many-to-many relationship, we can simply use has_and_belongs_to_many. However, to create an indirect association through a joint model, we can use has_many:through.

3. execJs: 'Could not find a JavaScript runtime' error.

To add gem 'execjs' gem 'therubyracer'in the gem file.

4. gem mysql sometimes triggers the following error:"incompatible character encodings: UTF-8 and ASCII-8BIT". Instead of using mysql, we need to use mysql2 which solved the problem. To install mysql2, you'll probably need to install the following package
sudo apt-get install mysql-client libmysqlclient-dev

5. To run rails app on port 80, the following command should be used
rvmsudo rails server -p 80 or rvmsudo rails server -p 80 -d

To stop the process, check the process id by typing cat tmp/pids/server.pid and then kill -9 the returned value.

6. Some very useful toolboxes.
Devise https://github.com/plataformatec/devise
Omniauth https://github.com/intridea/omniauth
Paperclip(rely on imagemagick) https://github.com/thoughtbot/paperclip,etc.
Kramdown http://kramdown.rubyforge.org/



Comments

Popular posts from this blog

InnovFest 2015

I attended the innovFest 2015 event. It was quite eye opening. Besides the booth, some topics in the forums also interested me. The first topic I joined was the Kopi Chat with Yossi Vardi, a famous Israeli entrepreneur and investor. He is straightforward and humorous. When talking about the most important reason why people wake up with a great idea but ended up sleeping without executing anything, he collected answers from the audiences. One answer pretty much fitted his appetite-- "People fear about losing faces". He shared his opinion with the quotes from Theodore Roosevelt, “It is not the critic who counts; not the man who points out how the strong man stumbles, or where the doer of deeds could have done them better. The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood; who strives valiantly; who errs, who comes short again and again, because there is no effort without error and shortcoming; but who does actually st

Time Goes By, So Fast

It's been a week since the last blog entry, time goes by so fast. This week's highlights: 1. Rethought about career development. http://www.douban.com/note/276145923/ 2. Treated my friends a traditional Shaoxing meal. 3. Started to learn Ruby on Rails. http://guides.rubyonrails.org/getting_started.html 4. Started to read the book "Simple and Usable Web, Mobile, and Interaction Design" by Giles Colborne. 5. Recorded some vocals. http://site.douban.com/shaohuan 6. Watched this Ted speech:  http://www.ted.com/talks/angela_lee_duckworth_the_key_to_success_grit.html 7. Followed Ahbei(founder of Douban) on Zhihu(Chinese version of Quora). 8. " 我认为世界上不存在一流的人才,世界上只有存在一流的人才一定是学习能力,谦虚,把自己当平凡的人" --马云(Jack Ma)

Consistency Matters

I didn't post anything last week, which means consistency has been broken. There's a need to reflect the task management skills, otherwise I'm very likely to driving the wrong road Priority changes. A good exercise would be to list the priorities down everyday and assign reasonable time to the tasks. Then never second-doubt. 100% focusing on the task when doing it. Priority changes from time to time.  Human minds are single-threaded, thus, we'll need to keep focused when doing one particular task. Be Grateful. I received the confirmation from NOC Israel that I got admitted by the programme and I'm heading to Israel next Jan:-) Thanks a lot for Prof.Ben and Karl's help. Ultimately, it might be a plan from God. Thanks every one. The additional interview from Google went well, however, I didn't get the winter intern opportunity this time. Though it's a bit too greedy to ask for too much, I still feel a bit sad after informed that I didn't get th