Skip to main content

Learning Ruby on Rails

 1. Polymorphic Association

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

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/ and then kill -9 the returned value.

6. Some very useful toolboxes.
Paperclip(rely on imagemagick),etc.


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

Challenges are just getting started

It's my first month working with real projects(my real, I mean something that's going to be used by the public). It's so different from school projects. Every detail matters, from the backend logic to the page buttons. These two weeks, I worked closely with two talented designers, one from a well-established startup company named Umeng Analytics and another doing his own startup after quitting a mobile gaming company named HappyLatte. I know the first designer,PJ, in a hackathon. He is really talented, should be the best designer I've ever worked with so far. I persuaded Prof.Tung to send me to Beijing to work with him on the first prototype and it turns out to be a right decision. He is not only good at design, but also good at UX. He reads a lot. He already came up with a wireframe of the project. Next week, he's going to finish designing the first round of UI design(around 15 pages). The market price for a very good designer is around 5k RMB(1k SGD)/page, however

2018 New Year Resolution

This year, let me try to draft the new year resolution based on the Willpower Instinct: Step 1:  List down the best things of the past year. 1. I proposed to my fiancee when she and her mum visited Singapore in July. We were then registered as officially married on her birthday on 28th Nov in Beijing. It was really the most important event of my life so far. After years' of long distance relationship, we finally made it. Though it will still take her another half year before coming to Singapore, we were both thankful that we really made it. 2. I bought my own apartment. It was a tough process to look for properties. I was so happy when I received the keys. Before that, I shared with my bedroom with my room mates for 3+ years. 3. Fooyo's sales was quite satisfying. We has two big customers, one in the Tourism Industry and another in the Logistics Industry. The products we produced were pretty pioneering and beneficial to the industry.  4. Fooyo succ