Web Developer Journal

2021 - A Year Look Back

Look back 2020 From the launch post, the blog until now (https://www.thanh.xyz/blog/blog-launch/), look back. This Blog now is 1 year old. :D This is just a small blog with limited content, luckily, there still some visitors. One of them has emailed me to ask about an issue, that makes me feel this blog is useful not only for me. :D Look forward to 2021 I updated the skin and migrate the website to Netlify.

Rails Application Templates

How do you start a new Rails project? As the very first guide we do like this: 1 rails new blog -d postgresql After that, you add some essentials gems and configuration, init Devise, add user controller… Devise: for authentication. Fiago: manage env variable. Replace Minitest by RSpec. etc… And then a new project comes, will you do the same? I think the answer is NO right?

Sanitizing params in Rails

The problem: Here is the example of data which POST from a client to API endpoint: 1 2 3 4 5 6 7 8 9 { "data": { "type": "entry", "attributes": { "title": " Chassidy Kozey re ", "content": " \n test n tag and spaces \n another " } } } In the content, there are whitespaces in the leading, trailing and, middle. Expectation: The spaces and the whitespaces should be removed from the leading and trailing.

How to override Bootstrap badge color

Html structure 1 2 3 4 5 td.sm-down-hidden - if payment? span.badge.badge-pill.badge-payment--verified = 'verified' - else span.badge.badge-pill.badge-payment--pending = 'pending' What does not work 1 2 3 4 5 6 7 8 9 10 11 12 .badge-payment { &--verified { background: $verified-background; color: $verified-color; } &--pending { background: $pending-background; color: $pending-color; } } What work 1 2 3 4 5 6 7 8 9 10 11 12 13 14 .

The colon in Ruby is quite confusing

The position of the colon in Ruby code confused me for a few days. 1. Before a text (:foo) 1 :hello In route definition 1 redirect_to :action => "edit", :id => params[:id] redirect_to method In the view 1 <%= link_to "Delete", article, confirm: "Are you sure?", method: :delete %> The method: :delete is quite confusing. It’s actually {method: :delete} :delete is not change in the application.

Page 2 of 3