Skip to content

Instantly share code, notes, and snippets.

Avatar
:octocat:

Juguang XIAO between40and2

:octocat:
View GitHub Profile
@between40and2
between40and2 / rails-bin.md
Created Jul 1, 2014
Scripts under bin directory of your Rails app
View rails-bin.md

bundle

#!/usr/bin/env ruby
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
load Gem.bin_path('bundler', 'bundle')

rails

@between40and2
between40and2 / -rails-routing-intro.md
Last active Aug 29, 2015
Rails Routing System components
View -rails-routing-intro.md

input part

use part

##Methodology to examine routing system.

Playing with Rails console

$ rails c
> app.main_app.routes  
    => #<ActionDispatch::Routing::RouteSet:0x007fe88539eae8> 
View rails-http-basic-digest-auth.md

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

@between40and2
between40and2 / rails-console.md
Last active Aug 29, 2015
Rails console tips
View rails-console.md

rails console

Model

> ActiveRecord::Base.connection.tables.map { |t| "#{t} => " + ActiveRecord::Base.connection.execute("select count(*) from #{t}").fetch_row.first}
@between40and2
between40and2 / rails-response.md
Last active Aug 29, 2015
This gist explains how to use render or redirect_to for HTTP response
View rails-response.md

render and redirect_to

To

@between40and2
between40and2 / form_for.md
Last active Aug 29, 2015
Comparing FormTagHelper, FormHelper, FormBuilder
View rails-routes-methods.md

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

View rake-db-seed.md

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.
View why-blog-here-for-work.md

Gist

Markdown

Use Tools! you civilized.

as team, efficiency.

You can’t perform that action at this time.