trabajo-afectivo/app/controllers/ticket_articles_controller.rb

62 lines
1.4 KiB
Ruby
Raw Normal View History

2012-04-10 14:06:46 +00:00
class TicketArticlesController < ApplicationController
before_filter :authentication_check
# GET /articles
def index
@articles = Ticket::Article.all
render :json => @articles
2012-04-10 14:06:46 +00:00
end
# GET /articles/1
def show
@article = Ticket::Article.find(params[:id])
render :json => @article
2012-04-10 14:06:46 +00:00
end
# POST /articles
def create
@article = Ticket::Article.new(params[:ticket_article])
@article.created_by_id = current_user.id
# find attachments in upload cache
@article['attachments'] = Store.list(
:object => 'UploadCache::TicketZoom::' + current_user.id.to_s,
:o_id => @article.ticket_id
)
if @article.save
# remove attachments from upload cache
Store.remove(
:object => 'UploadCache::TicketZoom::' + current_user.id.to_s,
:o_id => @article.ticket_id
)
2012-04-16 12:56:04 +00:00
render :json => @article, :status => :created
else
render :json => @article.errors, :status => :unprocessable_entity
2012-04-10 14:06:46 +00:00
end
end
# PUT /articles/1
def update
@article = Ticket::Article.find(params[:id])
if @article.update_attributes(params[:ticket_article])
render :json => @article, :status => :ok
else
render :json => @article.errors, :status => :unprocessable_entity
2012-04-10 14:06:46 +00:00
end
end
# DELETE /articles/1
def destroy
@article = Ticket::Article.find(params[:id])
@article.destroy
head :ok
2012-04-10 14:06:46 +00:00
end
end