Lawrence Sun

Hello World

Rails Notes: Deeply Nested Resources

Nested resources are commonly used in rails app. For example, 123456resources :books do resources :posts do resources :comments end resources :commentsend However, when it’s deeply-nested, th......

Rails Notes: Polymorphic Path

In my rails app, movie/book and post are in the polymorphic relationship. In posts/show.html.erb, I tried to add ‘Edit’ and ‘Delete’ function. The problem was how to write related path. At first, I......

华为路由器开启Web登陆

对于一台新的路由器来说,默认ip地址一般式是(192.168.1.1)。可以用一台PC连接路由器的任意lan口,并将PC的本地ip地址设为(192.168.1.x)(x一般取0~15,不为1),掩码(255.255.255.0),网关(192.168.1.1)。 但是昨天试图通过Web端来配置华为AR1220-S路由器的时候,一直无法连接。 在华为技术支持和网络资源的帮助下,发现原因可能是原......

Rails Notes: At or Reply to Someone

1. At The ‘@’ function is used widely on web apps. Here I use a jquery plugin called atwho. First download jquery.atwho.js, jquery.caret.js, jquery.atwho.css. Then add these files to app/assets. A......

Rails Notes: Link to Commentable

Few days ago I created a polymorphic comment model based on Railscasts. Today I wanted to show the lastest comments on homepage and link each comment body to their ‘parents’ like a book or a movie.......

How to Use Android Toggle Button

I am taking an online android course on Coursera. The first assignment is to build a app which could properly present text and image. Apart from what I learned from the first three lectures, I also......

Rails Notes: 利用七牛云储存Paperclip图片

之前使用Paperclip来实现Rails应用上传图片的功能, 但是在部署到Heroku时会有无法储存的问题, 每次push都会删除之前上传的图片。 这是因为Heroku不支持动态上传文件, 很多人碰到这种情况, Stackoverflow上推荐的解决方案是使用Amazon S3, 但是这个服务需要信用卡注册, 另外只能免费使用一年。 这无疑会提高试错和测试阶段的成本。经过另一番搜索, 发现......

Rails Notes: Make Dropdown Work on Heroku

After I deployed a app on Heroku, I found that the Bootstap dropdown menu didn’t work on Heroku. It was working in my local development environment. So I searched the answers from stackoverflow. It......

Rails Notes: Heroku Environment Configuration Problem

When I tried to deploy one of my rails app on Heroku, the following problem occured. 12can't convert nil into String /app/config/initializers/devise.rb:13:in `+' The reason was that I set DOMAIN_NA......

Rails Notes: Upload Avatar Using Paperclip

In my previous rails apps, I used gravatar_for method to link the gravatar to users. In a recent app, I wanted to add cover photos to the books and allow users to upload the images. So I decided to......