orbit-basic/app/controllers/desktop/co_authors_controller.rb

60 lines
1.6 KiB
Ruby
Raw Normal View History

class Desktop::CoAuthorsController < ApplicationController
def index
2012-12-05 10:15:58 +00:00
@co_authors = CoAuthor.where(name_id: current_user.id).order(["co_author desc"])
nils, not_nils = @co_authors.partition {|p| p.email.nil? }
@co_authors = not_nils + nils
2012-12-03 09:16:28 +00:00
@co_author_relations = CoAuthorRelation.all
respond_to do |format|
format.html { render :layout => false}
end
end
def new
@co_author = CoAuthor.new
2012-12-03 06:55:57 +00:00
@co_author_relations = CoAuthorRelation.all
respond_to do |format|
format.html { render :layout => false}
end
end
def edit
@co_author = CoAuthor.find(params[:id])
2012-12-03 09:16:28 +00:00
@co_author_relations = CoAuthorRelation.all
respond_to do |format|
format.html { render :layout => false}
end
end
def create
@co_author = CoAuthor.new(params[:co_author])
@co_author.name_id= current_user.id
if @co_author.save
2012-11-27 03:15:15 +00:00
render json: {success:true, msg: t('create.sucess.co_author')}.to_json
2012-11-21 06:52:26 +00:00
else
error_msg = @co_author.errors.full_messages.join("<br />")
render json: {success: false, msg: error_msg}.to_json
end
end
def update
@co_author = CoAuthor.find(params[:id])
if @co_author.update_attributes(params[:co_author])
2012-11-27 03:15:15 +00:00
render json: {success:true, msg: t('update.sucess.co_author')}.to_json
else
error_msg = @co_author.errors.full_messages.join("<br />")
render json: {success: false, msg: error_msg}.to_json
end
end
2012-11-30 16:21:49 +00:00
def destroy
@co_author = CoAuthor.find(params[:id])
@co_author.destroy
2012-12-03 06:04:23 +00:00
render :json => {success: true, msg: "Co-author deleted successfully!"}
2012-11-23 02:44:48 +00:00
end
end