"es-ar":
hello: "Hola mundo"
date:
formats:
default: ""
long: ""
short: ""
order: [ :day, :month, :year ]
...
Think the best of others
Monday, May 11, 2009
ruby on rails can't convert Symbol into String date_select, i18n
config/locales/es-ar.yml
Friday, May 8, 2009
ruby on rails, ActiveResource::Base, paginate, WillPaginate, RESTful xml resource and paginate
This sample assume that you have a service in the server that respond .xml
In the controller you may have conditions that are defined in the service, an example is a filter:
In the server service, in the controller you have:
This idea came from Gasper - Luis Guardiola
class NoteIntranet < ActiveResource::Base
self.site = INTRANET_CREDENTIALS[:site]
self.element_name = 'note'
cattr_reader :per_page
@@per_page = 20
def self.paginate(*args)
options = args.pop
@@per_page = options.delete(:per_page) || @@per_page
WillPaginate::Collection.create((options.delete(:page) || 1), @@per_page) do |pager|
all_elements = self.find(:all, options)
result = all_elements[pager.offset, pager.per_page].to_a
# inject the result array into the paginated collection:
pager.replace(result)
unless pager.total_entries
# the pager didn't manage to guess the total count, do it manually
pager.total_entries = all_elements.size
end
end
end
end
In the controller you may have conditions that are defined in the service, an example is a filter:
@notes = NoteIntranet.paginate(:page => params[:page], :params => { :title => params[:title] })
In the server service, in the controller you have:
@notes = Note.paginate(:page => params[:page], :conditions => ["title like '%?%'",params[:title]] )
This idea came from Gasper - Luis Guardiola
Wednesday, May 6, 2009
Wednesday, April 29, 2009
Flash Messages, System Messages, Ruby on Rails, by style, debug and test
controller:
views/layouts:
css out of dev, in test, this can help you in both environments:
flash[:notice] = "Correct things."
flash[:error] = "Alert things."
flash[:debug] = "Simple debug."
views/layouts:
<%- flash.each do |name, msg| -%>
<%= content_tag :div, msg, :id => "flash_#{name}" %>
<%- end -%>
css out of dev, in test, this can help you in both environments:
#debug{
display:none;
}
Monday, April 27, 2009
ruby on rails i18n
An approach:
$script/plugin install git://github.com/svenfuchs/rails-i18n.git
$cp config/locales/en.yml config/locales/es-ar.yml
config/environment.rb
app/views/payment_operation/show.html.erb
config/locales/es-ar.yml
$script/plugin install git://github.com/svenfuchs/rails-i18n.git
$cp config/locales/en.yml config/locales/es-ar.yml
config/environment.rb
config.time_zone = 'Buenos Aires'
config.i18n.default_locale = :"es-ar"
app/views/payment_operation/show.html.erb
<%= t('views.payment.show_title', :count => @foo.size, :bar => @foo.name) %>
config/locales/es-ar.yml
es-ar:
views:
payment:
show_title:
zero: "Mostrando operación de pago y {{bar}}."
one: "Mostrando operación de pago y {{bar}}."
many: "Mostrando operación de pago y {{bar}}."
Thursday, April 23, 2009
Ruby on Rails, model, validate alphanumeric and space characters
class Product < ActiveRecord::Base
...
validates_format_of :name, :with => /^([[:alpha:]]|[[:blank:]])+$/
Wednesday, April 22, 2009
Survive in php.. a logger method.
function logger($msg){
if(!isset($GLOBALS['logger'])){
$GLOBALS['logger'] = fopen("/var/www/apps/logs/dev.log","a");
}
fwrite($GLOBALS['logger'],"$msg\n");
}
function request($id = ''){
logger("dir/file.php::request(id[".$id."])");
...
}
Subscribe to:
Posts (Atom)