Skip to content

Instantly share code, notes, and snippets.

Avatar

Cẩm Huỳnh qcam

View GitHub Profile
View rails-link-to.md
@qcam
qcam / ruby-send.md
Created May 2, 2014
How to call a symbol method in Ruby
View ruby-send.md

How to call a symbol method in Ruby

class Klass
  def hello(*args)
    "Hello " + args.join(' ')
  end
end
k = Klass.new
k.send :hello, "gentle", "readers"   #=> "Hello gentle readers"
@qcam
qcam / rescue-error-rails.md
Last active Aug 29, 2015
Rescue Error in Controller
View rescue-error-rails.md

Use rescue_form to avoid code duplication in Controller

class DealsController < ApplicationController
  before_filter :authenticate_user!, except: [:index, :show, :list]
  before_filter :authenticate_proposer, only: [:edit]

  rescue_from StandardError, with: :show_errors
  rescue_from Order::OrderNotFound, with: :show_errors
  
View random-ruby-tips.md

##Ruby (Rails) tips

####1. Array Initialization

if x.is_a?(Array)
  x.each { |x| puts x } 
else
  puts x
end
@qcam
qcam / heroku-commands.md
Created May 3, 2014
Some Heroku helpful commands
View heroku-commands.md

Some Heroku commands

Open the bash shell

heroku run bash

Open Rails console

@qcam
qcam / voting-star-css.md
Created May 3, 2014
Voting star with CSS
View voting-star-css.md
  • Star Rating with only CSS
<div class="star-wrapper">
  <a class="star" href="javascript:alert(1)"></a>
  <div class="star-wrapper">
    <a class="star"></a>
    <div class="star-wrapper">
      <a class="star"></a>
      <div class="star-wrapper">
View CKEditor.md

Setup a WYSIWYG editor with CKEditor. Includes instruction for Rails_Admin

  • Add gem 'ckeditor' to your Gemfile and bundle
  • Checkout https://github.com/galetahub/ckeditor for instruction to generate the correct model to generate for uploading of files (eg. ActiveRecord + Paperclip)
  • Run rake db:migrate
  • Add //= require ckeditor/override in your application.js (before require_tree .)

To configure the editor to be used in Rails_Admin, follow this https://github.com/sferik/rails_admin/wiki/CKEditor

Sample Rails_Admin model config

@qcam
qcam / rails_admin-customise_authorisation.md
Last active Aug 29, 2015
How to customise authorisation rails_admin
View rails_admin-customise_authorisation.md

How to authorize rails_admin

config.authenticate_with do
  warden.authenticate!
end

config.authorize_with do
  redirect_to main_app.root_path unless current_user.has_role?(:admin)
end
@qcam
qcam / rvm-gemset.md
Created May 9, 2014
RVM Gemset commands
View rvm-gemset.md

get gemset list

rvm gemset list

empty gemset

rvm getmset empty [gemset_name]