Skip to content

Instantly share code, notes, and snippets.

View josevalim's full-sized avatar

José Valim josevalim

View GitHub Profile
# What I'm doing is:
<% form.buttons do %>
<%= pretty_positive_button 'Create user' %>
<%= pretty_negative_button 'Cancel' %>
<% end %>
# What I would like to do is:
<%= form.buttons :pretty_positive_button, :pretty_negative_button %>
# What we had to do:
<% semantic_form_for @post do |form| %>
<%= form.inputs :title, :created_at %>
<% form.semantic_fields_for @post.author do |author_form| %>
<% author_form.inputs do %>
<%= author_form.input :name %>
<%= author_form.input :posts_count %>
<% end %>
<% end %>
<% end %>
class ProjectsController < InheritedResources
def set_flash_message!(status, default_message)
message = if action_name == 'create' && status == :error
'This is a new message. Your project could not be created.'
else
default_message
end
flash[status] = message unless message.blank?
end
require 'autotest'
Autotest.add_hook :initialize do |at|
at.clear_mappings
# watch out: Ruby bug (1.8.6):
# %r(/) != /\//
at.add_mapping(%r%^spec/.*_spec.rb$%) { |filename, _|
filename
}
at.add_mapping(%r%^lib/(.*)\.rb$%) { |_, m|
@josevalim
josevalim / remarkable_way.rb
Created April 13, 2009 20:45
Comparision of Remarkable way with Rspec way of testing controllers
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe TasksController do
mock_models :task
describe :get => :index do
expects :find, :on => Task, :with => :all, :returns => mock_task
should_assign_to :tasks, :with => mock_task
describe Mime::XML do
module ActiveRecord
module Generators
class ModelGenerator < Base
# Line below is optional. If the generator name would be :model, the name
# below could be guessed.
#
# Generators are also public by default. If they are private it can be
# invoked only by other generators.
#
name :activerecord, :private => false
@josevalim
josevalim / quiz.rb
Created May 15, 2009 18:28 — forked from ryanb/quiz.rb
# COMMUNITY CHALLENGE
#
# How would you test this Quiz#problem method? Only two rules:
#
# 1. You must test the order the gets/puts happen. The tests should not
# still pass if "gets" happens before "puts", etc.
#
# 2. No changing the Quiz class implementation/structure. But you can
# use whatever framework you want for the tests.
#
module Remarkable
module Pending
# We cannot put the alias method in the module because it's a Ruby 1.8 bug
# http://coderrr.wordpress.com/2008/03/28/alias_methodmodule-bug-in-ruby-18/
#
def self.extended(base) #:nodoc:
class << base
alias_method_chain :example, :pending
class Amazing < Thor::Group
include Actions
def self.source_root
end
def copy
copy_file "my_file"
end
# Rails Generators invocations types.
#
# = PROBLEM
#
# 1) Rails should provide hooks for other generators in other to
# provide agnosticism.
#
# 2) Plugins/gems should be able to hook into another generator even
# if a hook is not there.