Skip to content

Instantly share code, notes, and snippets.

View francois-blanchard's full-sized avatar
😁

François Blanchard francois-blanchard

😁
View GitHub Profile
@francois-blanchard
francois-blanchard / disable_with_rails.md
Last active September 26, 2016 12:38
Disable button with ActionView helper

Disable button with ActionView helper

It's simple

Just have to add disable_with param like this :data => { disable_with: false }

submit_tag "Complete sale", data: { disable_with: "Submitting..." }
# => <input name="commit" data-disable-with="Submitting..." type="submit" value="Complete sale" />
@francois-blanchard
francois-blanchard / rails_associations_console.md
Created September 15, 2016 07:20
Get rails associations from console

Get rails associations from console

Project::EventSponsor.reflect_on_all_associations.each do |reflection|
  puts ":#{reflection.macro} => :#{reflection.name}"
end
@francois-blanchard
francois-blanchard / clean_local_branch_with_git_sweep.md
Last active August 24, 2016 09:49
How to clean branch git ? With git-sweep !

How to clean local branch git ? With git-sweep !

Install git-sweep

git-sweep it's a python library

Find documentation here

Use Pip to install :

@francois-blanchard
francois-blanchard / scope_no_relation.md
Last active May 12, 2016 08:20
scope for find no relation

scope for find no relation

class User < ActiveRecord::Base
  scope :without_tweet, -> { where.not(id: Tweet.select(:user_id).uniq) }
end

squash and commit

$ git checkout master
$ git merge --squash release_branch
$ git commit -m 'sprint #42'
$ git log
$ git push origin master
@francois-blanchard
francois-blanchard / presenters_in_rails.md
Last active April 27, 2016 14:38
Presenters in Rails

Presenters in Rails

Without presenter

View

<h1>@post.title</h1>
<span>@post.publication_status</span>

RSpec usage

Init for rails

  1. Remove /test directory, it’s minitest
  2. Install RSpec gem
# Gemfile

group :development , :test do
@francois-blanchard
francois-blanchard / scope_no_associations.md
Last active March 16, 2016 15:45
Scope for get objects with no association

Scope for get objects with no association

class User < ActiveRecord::Base
  has_many :messages
  scope :without_messages, -> { where.not(id: Message.select(:user_id).uniq.compact) }
end

class Message < ActiveRecord::Base
 belongs_to :user
@francois-blanchard
francois-blanchard / excel_to_csv.md
Last active January 27, 2016 13:00
Excel to csv (gem roo)

Excel to csv (gem roo)

documentation

class ExcelToCsv
  attr_accessor :input_path, :output_path, :col_sep

  def initialize(input_path:, output_path:, col_sep: ';')
 @input_path = input_path
@francois-blanchard
francois-blanchard / full_search_sunspot.md
Last active January 20, 2016 15:53
Full search specific fields with sunspot (SOLR)