examples/controllers/user_controller.rb in api-client-1.10.0 vs examples/controllers/user_controller.rb in api-client-2.0.0.rc1
- old
+ new
@@ -1,38 +1,45 @@
+# It will works with respond_with.
+# Your action should looks like any other one: A model with a method call. =D
class UserController < ApplicationController
- # It will works with respond_with.
- # Your action should looks like any other one: A model with a method call. =D
+ # It will hit http://api.example.com/users with a get request
def index
- @users = User.get("api.example.com/users")
+ @users = User.collection
respond_with(@users)
end
+ # It will initialize a new object based on the attribute accessors
def new
@user = User.new
respond_with(@user)
end
+ # It will hit http://api.example.com/users with a post request
def create
- @user = User.post("api.example.com/users", :user => params[:user])
+ @user = User.post("", :user => params[:user])
respond_with(@user)
end
+ # It will hit http://api.example.com/users/1 with a get request
def edit
- @user = User.get("api.example.com/users/#{params[:id]}")
+ @user = User.get(params[:id])
respond_with(@user)
end
+ # It will hit http://api.example.com/users/1 with a patch request
def update
- @user = User.patch("api.example.com/users", { :id => params[:id], :user => params[:user]})
+ @user = User.patch("", { :id => params[:id], :user => params[:user] })
respond_with(@user)
end
+ # It will hit http://api.example.com/users/1 with a get request
def show
- @user = User.get("api.example.com/users/#{params[:id]}")
+ @user = User.get(params[:id])
respond_with(@user)
end
+ # It will hit http://api.example.com/users/1 with a delete request
def delete
- @user = User.delete("api.example.com/users/#{params[:id]}")
+ @user = User.delete(params[:id])
respond_with(@user)
end
-end
+end
\ No newline at end of file