Skip to content

Instantly share code, notes, and snippets.

View between40and2's full-sized avatar

Juguang XIAO between40and2

  • London & Beijing
View GitHub Profile

root.rb

application.rb

Here is note in that file

# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers

-- all .rb files in that directory are automatically loaded.

@between40and2
between40and2 / rails-initializers.md
Last active August 29, 2015 14:02
This is enlightened by ...

Rails Initializers

Be sure to restart your server when you modify this file.

backtrace_silencers.rb

You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.

Gist

Markdown

Use Tools! you civilized.

as team, efficiency.

rake db:seed rake aborted! SystemStackError: stack level too deep

Most probably, you either:

  • use after_create, to make it call recursively ; or
  • call save! in before_create, to make it call recursively.

Paths come with marketing and perception identity purpose, while controller-action is purely technical. Routes decouples these two parts to make it flexible and controller-action reusable.

Tips

Different paths may lead to same controller-action. That is where you need to apply :defaults options to differentiate the paths. controller-action can check params on the defaults. For example, both account creation form and account registration form can share the same accounts#new. :default can be set with usecase: creation or usecase: registration respectively.

:as option is encouraged to apply, so that in your controller or view you can use named path/url to refer to the link. This sets flexibility when you change paths frequently. This is especially handy for routes in engine/plugin, since you cannot predicate how a hosting app set path for engine itself when in use.

No such thing like redirect in route. You can just refer the path to controller-action you want it to be. Example: `root 'cc\t

@between40and2
between40and2 / form_for.md
Last active August 29, 2015 14:02
Comparing FormTagHelper, FormHelper, FormBuilder
@between40and2
between40and2 / rails-response.md
Last active August 29, 2015 14:02
This gist explains how to use render or redirect_to for HTTP response

render and redirect_to

To

@between40and2
between40and2 / rails-console.md
Last active August 29, 2015 14:02
Rails console tips

rails console

Model

> ActiveRecord::Base.connection.tables.map { |t| "#{t} => " + ActiveRecord::Base.connection.execute("select count(*) from #{t}").fetch_row.first}

@between40and2
between40and2 / rails-http-basic-digest-auth.md
Created June 23, 2014 09:03
HTTP Basic/Digest Auth in Rails

ActionController::HttpAuthentication::Basic::ControllerMethods

  • authenticate_or_request_with_http_basic(realm = "Application", &login_procedure)
  • authenticate_with_http_basic(&login_procedure)
  • request_http_basic_authentication(realm = "Application")

ActionController::HttpAuthentication::Digest::ControllerMethods