views:

34

answers:

1

Hi ,

i am new to ROR

i am having an api code for blogs in my application . this includes the function create,show,update .

I am trying to write sample Api code in Ruby for this. How to write this ??

Please give suggestions.

My Create code is

 def create

@blogpost = Blogpost.new(params[:blogpost])
@blogpost.user = current_user

respond_to do |format|
  if @blogpost.save
    check_for_pingbacks(@blogpost)
    format.html { redirect_to root_path }
    format.xml  { render :xml => @blogpost.to_xml(to_any_options) }
    format.json { render :json => @blogpost.to_json(to_any_options) }
  else
    format.html {redirect_to root_path }
    format.xml  { render :xml => @blogpost.errors, :status => :unprocessable_entity }
    format.json  { render :json => @blogpost.errors, :status => :unprocessable_entity }
  end
end
 else
  respond_to do |format|
    error=Hash.new
    error[:error]="Only Post Request is Allowed"
    format.xml {render :xml=>error.to_xml({:root=>'errors'})}
    format.json {render :json=>error.to_json({:root=>'errors'})}
  end
end
end
A: 

If I understand correctly, it looks like you want to generate RDocs for your app? Rails has built-in support for doing this with the following rake task:

rake doc:app

This will generate documentation in /doc/app/ of your app.

As for writing RDoc, there are plenty of resources out there, the RDoc documentation itself is a good place to start: http://rdoc.sourceforge.net/doc/index.html

Sidane