0
我是ROR新手API的示例Ruby api代碼 - 博客帖子
我在我的應用程序中有博客的api代碼。這包括創建,顯示,更新功能。
我想在Ruby中爲此編寫示例Api代碼。如何寫這個?
請給出建議。
我創建的代碼是
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