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