Je suis nouveau àExemple de code Ruby api pour API - BlogPosts
RORj'ai un code d'api pour les blogs dans ma demande. ceci inclut la fonction créer, montrer, mettre à jour. J'essaie d'écrire un exemple de code Api dans Ruby pour cela. Comment écrire ceci ??
Veuillez donner des suggestions.
Mon Créer un code est
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