Yu-Chieh’s Blog (Y.C. Chang)

Ruby on Rails / Rubygems / FullStack / Git / Mac notes.

Error Message on Brew Install: Error: SHA1 Mismatch

  • Sometimes we might get error message when we use brew install xxxxx_package.
  • What can we do to solve this?
  • We could just remove the package which we already download.

  • e.g.

1
2
3
4
5
6
7
...
Error: SHA1 mismatch
...
$ rm /Library/Caches/Homebrew/libpng-1.6.16.tar.xz
# and install it again
$ brew install libpng
...
  • done.

Heroku Command Line Tips

1
2
3
4
5
6
$ heroku apps:rename NEW_APP_NAME # for rename app
$ heroku create NEW_APP_NAME # for create new name
$ heroku pg:reset DB_NAME # for reset DB
$ git remote add heroku git@heroku.com:project.git
$ heroku git:remote -a APP_NAME
$ heroku keys:add

Rails Tip: How to Update Attributes Without Save

  • generally, when we use update_attributes, it will save automatically. however, what if we just want to new an record and update some attributes of it. what can we do?

  • We can use assign_attributes method.

1
2
3
4
user = User.new
user.assign_attributes({ :name => 'Andy'})
user.name        # => "Andy"
user.new_record? # => true

How to Install and Deploy Redmine 2.6.x on Heroku

1
2
$ git clone https://github.com/redmine/redmine.git -b 2.6-stable
$ cd redmine
  • remove those files from .gitignore
1
2
3
4
5
6
7
Gemfile.lock
Gemfile.local
public/plugin_assets 
config/initializers/session_store.rb 
config/initializers/secret_token.rb 
config/configuration.yml 
config/email.yml

How to Fix Simple Search of Octopress

find navigation.html in /source/_includes and replace original code with new code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
...
<form action="https://www.google.com/search" method="get">
  <fieldset role="search">
<!-- original code  -->
<!--     <input type="hidden" name="q" value="site:andystu.github.io" /> -->
<!-- //original code  -->

<!-- new code -->
    <input type="hidden" name="sitesearch" value="andystu.github.io" />
<!-- //new code -->
    <input class="search" type="text" name="q" results="0" placeholder="Search"/>
  </fieldset>
</form>
...

done.

reference http://kaspars.net/blog/wordpress/how-to-add-google-site-search

How to Get a List of a Class or Instance Methods by Keyword

a very useful tip to find methods in ruby/rails console

1
2
3
4
5
6
7
8
# Class.methods.grep(/keyword/) 

# e.g. 
irb> 1.methods.grep(/to/) #  => [:to_s, :to_f, :to_default_s, :to_json, :upto, :downto, :to_i, :to_int, :numerator, :denominator, :to_r, :to_bn, :to_d, :singleton_method_added, :to_c, :to_formatted_s, :to_param, :to_query, :psych_to_yaml, :to_yaml, :to_yaml_properties, :singleton_class, :singleton_methods, :respond_to?, :singleton_method, :define_singleton_method, :to_enum]

# Class.instance_methods.grep(/method/) #  => [:instance_methods, :public_instance_methods, :protected_instance_methods, :private_instance_methods, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods]

# Class.methods.grep(/new/) # => ["new"]

How to Fix Octopress Build Warning Layout Nil Requested After Installing Some Themes

How to fix Octopress “build warning Layout nil requested”

After changing some themes of octopress then rake generate might produce some errors like this: Build Warning: Layout 'nil' requested in .....atom.xml does not exist.

Fix by replacing:

layout: nil with: layout: null in files: source/atom.xml source/robots.txt source/_includes/custom/category_feed.xml

Ujs / Sjr Usage Hint

ujs / sjr usage hint for rails link_to method and form!

1
2
3
4
5
6
7
8
9
10
11
A. Enable feature of ajax for Link
  1. link_to 要加 remote: true, path 要是 .js 的 format
  2. 要確保後端 action 支援 .js format
  3. 必須要有 #{action}.js.erb

B. Enable feature of ajax for Form
  1. form_for(@record, format: :js, remote: true)
  2. 確保後端 action 支援 .js format
  3. 必須要有 #{action}.js.erb

對應的 js.erb 必須處接下來的事情 e.g. 刪除資料、redirects、update forms ... etc