Skip to content

Instantly share code, notes, and snippets.

@pramatias
Created January 13, 2011 16:45
Show Gist options
  • Save pramatias/778151 to your computer and use it in GitHub Desktop.
Save pramatias/778151 to your computer and use it in GitHub Desktop.
#config/routes.rb
ActionController::Routing::Routes.draw do |map|
map.resources :chatters do |chatter|
chatter.resources :chats
end
#app/controllers/chats_controller.rb
#Parameters: {"chat"=>{"id"=>"1", "message"=>"cool"}}
class ChatsController < ApplicationController
# GET /chats
# GET /chats.xml
def find_by_id
logger.info "The params Id is #{params['chat']['id']}"
@chats = Chat.find(:first, :conditions => {:id => params["chat"]["id"] })
respond_to do |format|
#format.html # index.html.erb
format.xml { render :xml => @chats.id }
end
end
#app/controllers/chatters_controller.rb
#Parameters: {"chatter"=>{"name"=>"second_chatter"}}
class ChattersController < ApplicationController
# GET /chatters
# GET /chatters.xml
def find_by_name
logger.info "The params Id is #{params['chatter']['name']}"
@chatters = Chatter.find(:first, :conditions => {:name => params["chatter"]["name"] })
respond_to do |format|
#format.html # index.html.erb
format.xml { render :xml => @chatters.id }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment