orbit-basic/app/controllers/desktop/co_author_relations_control...

64 lines
1.9 KiB
Ruby
Raw Normal View History

2012-12-03 04:10:45 +00:00
class Desktop::CoAuthorRelationsController < ApplicationController
def index
@co_author_relations = CoAuthorRelation.all
new
respond_to do |format|
format.html {render layout: false }
end
end
2012-12-05 09:49:41 +00:00
def edit
@co_author_relation = CoAuthorRelation.find(params[:id])
2012-12-05 10:02:42 +00:00
respond_to do |format|
format.html { render :layout => false}
end
2012-12-05 09:49:41 +00:00
end
2012-12-03 04:10:45 +00:00
def new
2012-12-05 10:24:50 +00:00
@co_author_relation = CoAuthorRelation.new
2012-12-03 04:10:45 +00:00
end
def create
2012-12-05 10:24:50 +00:00
@co_author_relation = CoAuthorRelation.new(params[:co_author_relation])
2012-12-05 07:09:58 +00:00
@co_author_relations = CoAuthorRelation.all
2012-12-03 04:10:45 +00:00
2012-12-05 10:24:50 +00:00
if @co_author_relation.save
2012-12-05 07:09:58 +00:00
newv = render_to_string partial: "show_form", object: @co_author_relations
2012-12-05 10:58:43 +00:00
render json: {success: true, msg: "New Relation successfully saved!", newvalue: newvm}.to_json
2012-12-03 04:10:45 +00:00
else
2012-12-05 10:24:50 +00:00
error_msg = @co_author_relation.errors.full_messages.join("<br />")
2012-12-03 04:10:45 +00:00
render json: {success: false, msg: error_msg}.to_json
end
end
2012-12-05 09:49:41 +00:00
def update
@co_author_relation = CoAuthorRelation.find(params[:id])
if @co_author_relation.update_attributes(params[:co_author_relation])
2012-12-05 10:58:43 +00:00
@co_author_relations = CoAuthorRelation.all
newv = render_to_string partial: "show_form", object: @co_author_relations
render json: {success: true, msg: "New Relation successfully updated!", newvalue: newv}.to_json
2012-12-05 09:49:41 +00:00
else
error_msg = @co_author.errors.full_messages.join("<br />")
render json: {success: false, msg: error_msg}.to_json
end
end
2012-12-03 04:10:45 +00:00
def destroy
@co_author_relation = CoAuthorRelation.find(params[:id])
@co_author_relation.destroy
2012-12-05 06:51:12 +00:00
reset_co_author_relation
2012-12-03 04:10:45 +00:00
render :json => {success: true, msg: "deleted successfully!"}
end
2012-12-05 06:51:12 +00:00
private
def reset_co_author_relation
co_author = CoAuthor.where(co_author_relations_id: @co_author_relation.id)
co_author.map do |c|
c.update_attributes(co_author_relations_id: nil)
end
end
2012-12-03 04:10:45 +00:00
end