Skip to content

Instantly share code, notes, and snippets.

View mytrile's full-sized avatar

Dimitar Kostov mytrile

View GitHub Profile
def show
@category ||= Category.find(params[:id])
end
def index
@category = Category.find(:all)
@cat = Category.new
respond_to do |format|
format.html
format.xml { render :xml => @category }
format.json { render :json => @category }
end
end
def destroy
if Category.destroy(params[:id])
flash[:notice] = 'Category successfully deleted !'
redirect_to :action => "index"
else
flash[:error] = 'There was an error processing your request'
redirect_to :action => "index"
end
end
@mytrile
mytrile / user.rb
Created January 8, 2009 19:00 — forked from tokumine/user.rb
# Username or email login for restful_authentication in user.rb model
def self.authenticate(login, password)
return nil if login.blank? || password.blank?
u = find_in_state :first, :active, :conditions => ["email = ? OR login = ?",login,login] # need to get the salt
u && u.authenticated?(password) ? u : nil
end
We couldn’t find that file to show.
def create
user = User.find_by_login(current_user.login)
@category = Category.new(params[:category])
if user.categories.create params[:category]
flash[:notice] = 'Category successfully added !'
redirect_to(categories_url)
else
flash[:notice] = 'There was an error processing your request'
redirect_to(categories_url)
end
# run by doing:
# rake locales:compile LANG_TARGET=pt-BR
namespace :locales do
desc "Compare locale files and get differences and missing keys"
task :compile do
ENV['LANG_SOURCE'] = 'en' if ENV['LANG_SOURCE'].nil?
if ENV['LANG_TARGET'].nil?
puts "define the target language using the LANG_TARGET environment variable\nrake locales:compile LANG_TARGET=pt-BR"
exit(1)
end
task :create_db do
ruby "migrate.rb"
end
class Account < ActiveRecord::Base
belongs_to :user
has_many :bills
has_many :expenses
validates_presence_of :name, :message => "You didn't provide account name"
validates_length_of :name, :minimum => 4,
:message => "Account name must be 4 characters minimum",
:on => :create
#] results_per_page=15 since_id=0 total=1>, @query={:q=>["httparty", "from:jnunemaker"]}>