ActiveRecord Class Example
class Task < ActiveRecord::Base belongs_to :user belongs_to :location belongs_to :project end .
DZone Snippets > Ruby on Rails
11280 users tagging and storing useful source code snippets
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
class Task < ActiveRecord::Base belongs_to :user belongs_to :location belongs_to :project end .
module Bezurk #:nodoc: module ActiveRecord #:nodoc: module Extensions def to_conditions attributes.inject({}) do |hash, (name, value)| hash.merge(name.intern => value) end end alias :to_conditions_hash :to_conditions end end end ActiveRecord::Base.send(:include, Bezurk::ActiveRecord::Extensions)
#codename generated from the dictionary REVISION_NUMBER = `svn info`.split("\n")[4][/\d+/].to_i APP_CODENAME = IO.readlines("/usr/share/dict/words")[REVISION_NUMBER]
APP_VERSION = IO.popen("svn info").readlines[4]
if @logged_in_client page.replace_html "message", :partial => 'shared/bad_login' else page.redirect_to "whatever you want here" end
render :update do |page| if @logged_in_client page.replace_html "message", :partial => 'shared/bad_login' else page.redirect_to "whatever you want here" end end
# view <%= form_tag :controller => :posts, :action => create %> <%= text_field("post", "title", "size" => 20) %> <%= text_field("user", "email", "size" => 20) %> <%= end_form_tag %>
# posts_controller class PostsController < ApplicationController def create @post = Post.create(params[:post]) @user = User.create(params[:user]) @post.users << @user end end
def file=(new_file) new_file.rewind image = Magick::Image::from_blob(new_file.read).first end