Skip to content

Instantly share code, notes, and snippets.

Avatar
:octocat:

Juguang XIAO between40and2

:octocat:
View GitHub Profile
@between40and2
between40and2 / rails-css-js-seamless-integration
Last active Aug 29, 2015
How to make UI+JS staff working with Rails projects seamlessly
View rails-css-js-seamless-integration
make design-work (css+js) a Rails mountable plugin.
- Install Rails on designer's machine.
- create a Rails mountable plugin, and put it in svn.
- let designers edit assets files, while browsing Rails running server.
understand sprocket and its limitations.
- expose all that are 'required' files into one big file to output.
@between40and2
between40and2 / rails-plugin-and-scaffold-css.md
Last active Aug 29, 2015
Rails Plugin and scafford css
View rails-plugin-and-scaffold-css.md

Rails Plugin

With my experience with Rails 4.0.5 so far, to my own naivety, I found that the error message displayed in form is different from the normal Rails app. The root cause is that 'scaffold.css' is not included.

Code generated by scaffold

<div class="field">
 <%= f.label :password %><br>
 <%= f.password_field :password %>
@between40and2
between40and2 / rails-console-migration-cheatsheet.md
Last active Aug 29, 2015
You can do a lot of things in rails console. Here we just tip on migration part.
View rails-console-migration-cheatsheet.md

How database/table related info

Account.table_name
Account.columns.collect {|x| x.name}

Change table structure

Even you can do rails g migration in cli, which is also persisted to share. Here is a quick and dirty way.

@between40and2
between40and2 / rails-initializers.md
Last active Aug 29, 2015
This is enlightened by ...
View rails-initializers.md

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.

View rails-init-process.md

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

Gist

Markdown

Use Tools! you civilized.

as team, efficiency.

@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