Skip to content

Instantly share code, notes, and snippets.

View filiperocha's full-sized avatar

Filipe Rocha filiperocha

View GitHub Profile
def link_to_add_fields(name, f, association)
new_object = f.object.class.reflect_on_association(association).klass.new
fields = f.fields_for(association, [new_object], :child_index => "new_#{association}") do |builder|
render(association.to_s.singularize + "_fields", :f => builder)
end
link_to_function(name, h("add_fields(this, \"#{association}\", \"#{escape_javascript(fields)}\")"))
end
This example shows how to setup an environment running Rails 3 beta 3 under 1.9.2-head with a 'rails3' gem set.
∴ rvm update --head
# ((Open a new shell)) or do 'rvm reload'
# If you do not already have the ruby interpreter installed, install it:
∴ rvm install 1.9.2-head
# Switch to 1.9.2-head and gemset rails3, create if it doesn't exist.
∴ rvm --create use 1.9.2-head@rails3
class PagesController < ApplicationController
before_filter :login_required, :except => [ :show ]
# GET /pages
# GET /pages.xml
def index
@pages = Page.find(:all)
respond_to do |format|
format.html # index.html.erb
# Everything you need to do to get started with Rails 2.3.8
#
# As of June 14th, 2010 @ 2:30 p.m. MST
#
# This gist now features instructions to get Rails 3 up and running with:
# - Ruby 1.8.7-p174
# - Bundler 0.9.26
# - Cucumber 0.8.0
# - Rspec 1.3.0 + Rspec-Rails 1.3.2
# - RVM
@filiperocha
filiperocha / devise.pt-PT.yml
Created June 28, 2010 11:47
Portuguese (Portugal) translation for devise (http://github.com/plataformatec/devise)
pt-PT:
errors:
messages:
not_found: "não encontrada"
already_confirmed: "já foi confirmada"
not_locked: "não se encontra bloqueada"
devise:
failure:
unauthenticated: 'Necessita de entrar ou registar-se no sistema antes de continuar.'
module CouchDBAttachments
def attachment(*args)
lambda do |env|
request = ActionDispatch::Request.new(env)
doc = DocWithAttachments.get(request.params[:doc])
serve_attachment(doc, request.params[:path])
end
end
private
module CouchDBAttachments
def attachment(*args)
lambda do |env|
request = ActionDispatch::Request.new(env)
doc = DocWithAttachments.get(request.params[:doc])
serve_attachment(doc, request.params[:path])
end
end
private
#Selector de idioma
#dependencias:
# 1 - Rack locale del paquete Rack-contrib [1]
# USO: Se usa para detectar el idioma definido por el usuario en su browser ['HTTP_ACCEPT_LANGUAGE']
# Esplicado aquí http://guides.rubyonrails.org/i18n.html#using-accept-language
# [1] http://github.com/rack/rack-contrib
# 2 - Routing-filter [1]
# USO: Establecer el locale en las URLs ej.: www.mysite.com/es/foo/bar
# NOTA: Si tambien quieres traducir las URL's usa la gema de Raul Murciano Translate_routes [2] (De momento sin cobertura para Rails3)
if params[:_search] == "true" && params[:filters].present?
filters = Hash.new
j = JSON.parse(params[:filters])
i=0
until j.fetch("rules").size == i
k = j.fetch("rules").to_a[i].values_at("field", "op", "data", "groupOp")
if k[1] == "cn"
k[1] = "matches"
@filiperocha
filiperocha / my_template.rb
Created May 17, 2012 14:09 — forked from xavierRiley/my_template.rb
Kyan Custom Admin Template for Padrino
project :test => :rspec, :orm => :activerecord, :adapter => :postgres, :mock => :none, :script => :jquery, :renderer => :erb, :stylesheet => :none, :admin_renderer => :erb
# include additional generators
inject_into_file destination_root('config/boot.rb'), "\# include additional generators\nPadrino::Generators.load_paths << Padrino.root('generators', 'kyan_admin_page_generator.rb')\nPadrino::Generators.load_paths << Padrino.root('generators', 'kyan_admin_generator.rb')\n\n", :before => "Padrino.load!"
say "Cloning custom generators from [email protected]:xavierRiley/Kyan-Padrino-Admin-Generators.git", :red
remove_dir destination_root('generators')
run "git clone [email protected]:xavierRiley/Kyan-Padrino-Admin-Generators.git " + destination_root('generators')
#generate :model, "account username:string password:string"