Posts Tagged ‘rails’

query interface

find_all : return multiple records
_by_* : replace * with your column
(false) : where complete like ‘false’
def incomplete
@tasks = Task.find_all_by_complete(false)
end
find : return single record
_by_* : replace * with your column
(false,:order => ‘created_at’ DESC) : where complete like ‘false’ and order by created_at descending
def last_incomplete
@task = Task.find_by_complete(false, :order => ‘created_at DESC’)
end

Session with rails

Session Register
[code="ruby"]
@current_member = Member.find_by_username_and_passwd(params[:username], params[:passwd])
unless @current_member.nil?
session[:user_id]=@current_member.id
end
[/code]
Query with Session
[code="ruby"]
unless session[:user_id].blank?
@current_user = Member.find_by_id(session[:user_id])
end
[/code]
Session Destroy
[code="ruby"]
session[:user_id]=@current_user=nil
[/code]

Tags: , ,

RAILS : link_to with specific URLs

[code="ruby"]

[/code]

Tags: , ,

RAILS - Link to ‘action’

ProjectController
[code="ruby"]
class ProjectController < ApplicationController
def index
@p=Project.find(:all);
end
end
[/code]
indexView
[code="ruby"]
Project#index

’show’,:id=>p.id}%>

[/code]

Tags: ,

Note : mongrel_cluster

1. CLUSTER CONFIGURATION
root@ruby:/app/# mongrel_rails cluster::configure -e RAILS-ENV -p PORT -a IP_ADDRESS -PROCS_NO
2. CLUSTER START
root@ruby:/app/# mongrel_rails cluster::start

Tags: , , ,