This repository has been archived on 2024-03-16. You can view files and clone it, but cannot push or open issues or pull requests.
orbit-4-1/app/controllers/desktop/co_authors_controller.rb

58 lines
1.5 KiB
Ruby

class Desktop::CoAuthorsController < ApplicationController
def index
@co_authors = CoAuthor.where(name_id: current_user.id)
@co_author_relations = CoAuthorRelation.all
respond_to do |format|
format.html { render :layout => false}
end
end
def new
@co_author = CoAuthor.new
@co_author_relations = CoAuthorRelation.all
respond_to do |format|
format.html { render :layout => false}
end
end
def edit
@co_author = CoAuthor.find(params[:id])
@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
render json: {success:true, msg: t('create.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
def update
@co_author = CoAuthor.find(params[:id])
if @co_author.update_attributes(params[:co_author])
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
def destroy
@co_author = CoAuthor.find(params[:id])
@co_author.destroy
render :json => {success: true, msg: "Co-author deleted successfully!"}
end
end