I am rookie in rails restful web service and i am trying build service that returns a json dump of deals.So far my app returns these deals in json format when you hit http://localhost:3000/api/deals. Now i want to add two mandatory parameters(deal_id and title) and two optional parameters in the uri http://localhost:3000/api/deals?deal_id=2&title=book
. What is the best way to validate these two mandatory parameters. Assuming Deal model has fields deal_id, title, description and vendor.
Here is my code
Controller
module Api
class DealsController < ApplicationController
respond_to :json
def index
@deals = Deal.all
respond_with (@deals)
end
end
end
routes
namespace :api,:defaults => {format:'json'} do
resources :deals
end
Aucun commentaire:
Enregistrer un commentaire