From 78500e06612a5d77524c287c5c2386251aa25cc8 Mon Sep 17 00:00:00 2001 From: Rueshyna Date: Thu, 22 Nov 2012 10:49:54 +0800 Subject: [PATCH] fixed add journal and co-author curd problem, but have redirect problem... --- .../javascripts/desktop/journal_pages.js.erb | 1 - .../desktop/co_authors_controller.rb | 18 +++++++----------- .../desktop/journal_pages_controller.rb | 17 +++++++++-------- app/views/desktop/co_authors/_form.html.erb | 15 ++------------- app/views/desktop/co_authors/edit.html.erb | 2 +- app/views/desktop/co_authors/new.html.erb | 2 +- app/views/desktop/journal_pages/_form.html.erb | 10 ---------- 7 files changed, 20 insertions(+), 45 deletions(-) diff --git a/app/assets/javascripts/desktop/journal_pages.js.erb b/app/assets/javascripts/desktop/journal_pages.js.erb index 2c6821da..139f94fc 100644 --- a/app/assets/javascripts/desktop/journal_pages.js.erb +++ b/app/assets/javascripts/desktop/journal_pages.js.erb @@ -1,6 +1,5 @@ orbitDesktop.prototype.initializeJournalPapers = function(target,url,cache){ // this init journal papers this.initializeJournalPapers.formCallback = function(data){ - if(data.success){ o.notify(data.msg,"success"); o.sub_menu_item($("div[content-type=menu] a").eq(0)); }else{ diff --git a/app/controllers/desktop/co_authors_controller.rb b/app/controllers/desktop/co_authors_controller.rb index 9b0d3bd1..1c74314e 100644 --- a/app/controllers/desktop/co_authors_controller.rb +++ b/app/controllers/desktop/co_authors_controller.rb @@ -36,24 +36,20 @@ class Desktop::CoAuthorsController < ApplicationController @co_author = CoAuthor.new(params[:co_author]) @co_author.name_id= current_user.id - if @writing_journal.save - render :json => {success:true, msg: "Paper successfully saved!"}.to_json + if @co_author.save + render json: {success:true, msg: "Co-author successfully saved!"}.to_json else - render :json => {success:false, msg: "Saving failed!"} + render json: {success: false, msg: @co_author.errors.full_messages}.to_json end end def update @co_author = CoAuthor.find(params[:id]) - respond_to do |format| - if @co_author.update_attributes(params[:co_author]) - format.html { redirect_to desktop_co_authors_url, notice: 'CoAuthor was successfully updated.' } - format.json { head :no_content } - else - format.html { render action: "edit" } - format.json { render json: @co_author.errors, status: :unprocessable_entity } - end + if @co_author.update_attributes(params[:co_author]) + render json: {success:true, msg: "Co-author successfully update!"}.to_json + else + render json: {success: false, msg: @co_author.errors.full_messages}.to_json end end diff --git a/app/controllers/desktop/journal_pages_controller.rb b/app/controllers/desktop/journal_pages_controller.rb index b389dca6..b6acd5d4 100644 --- a/app/controllers/desktop/journal_pages_controller.rb +++ b/app/controllers/desktop/journal_pages_controller.rb @@ -1,4 +1,5 @@ class Desktop::JournalPagesController < ApplicationController + #before_filter :check_for_cancel, :only => [:create, :update] def index @writing_journal = WritingJournal.where(create_user_id: current_user.id) @@ -35,14 +36,14 @@ class Desktop::JournalPagesController < ApplicationController end def create - params[:writing_journal][:create_user_id] = current_user.id - @writing_journal = WritingJournal.new(params[:writing_journal]) + params[:writing_journal][:create_user_id] = current_user.id + @writing_journal = WritingJournal.new(params[:writing_journal]) - if @writing_journal.save - render json: {success: true, msg: "Paper successfully saved!"}.to_json - else - render json: {success: false, msg: "Saving failed!"}.to_json - end + if @writing_journal.save + render json: {success: true, msg: "Paper successfully saved!"}.to_json + else + render json: {success: false, msg: @writing_journal.errors.full_messages}.to_json + end end def update @@ -52,7 +53,7 @@ class Desktop::JournalPagesController < ApplicationController if @writing_journal.update_attributes(params[:writing_journal]) render json: {success: true, msg: "Paper successfully saved!"}.to_json else - render json: {success: false, msg: "Saving failed!"}.to_json + render json: {success: false, msg: @writing_journal.errors.full_messages}.to_json end end end diff --git a/app/views/desktop/co_authors/_form.html.erb b/app/views/desktop/co_authors/_form.html.erb index 22b8433e..e5d9e8ff 100644 --- a/app/views/desktop/co_authors/_form.html.erb +++ b/app/views/desktop/co_authors/_form.html.erb @@ -1,17 +1,6 @@ -<% if @co_author.errors.any? %> -
-

<%= pluralize(@co_author.errors.count, "error") %> prohibited this user from being saved:

- -
-<% end %>
- - <%= button_tag "Save", name: "commit", value: "Save", class: "fn_btn hh2 thmc2 thmtxt" %> - <%= button_tag "Cancel", name: "commit", value: "Cancel", class: "fn_btn hh2 thmc2 thmtxt" %> + <%= f.submit "Save", name: "commit", value: "Save", class: "fn_btn hh2 thmc2 thmtxt" %> +
diff --git a/app/views/desktop/co_authors/edit.html.erb b/app/views/desktop/co_authors/edit.html.erb index 2f48f4c5..015f6321 100644 --- a/app/views/desktop/co_authors/edit.html.erb +++ b/app/views/desktop/co_authors/edit.html.erb @@ -1,3 +1,3 @@ -<%= form_for @co_author, url: desktop_co_author_path(@co_author) do |f| %> +<%= form_for @co_author, html: { multipart: true ,"form-type"=>"ajax_form", "callback-method"=>"coAuthorformCallback"} , url: desktop_co_author_path(@co_author) do |f| %> <%= render partial: 'desktop/co_authors/form', locals: {:f => f} %> <% end %> diff --git a/app/views/desktop/co_authors/new.html.erb b/app/views/desktop/co_authors/new.html.erb index c794f218..1a4ec2d5 100644 --- a/app/views/desktop/co_authors/new.html.erb +++ b/app/views/desktop/co_authors/new.html.erb @@ -1,3 +1,3 @@ -<%= form_for @co_author, html: { multipart: true ,:type=>"ajax_form", "callback-method"=>"coAuthorformCallback"} , url: desktop_co_authors_path do |f| %> +<%= form_for @co_author, html: { multipart: true ,"form-type"=>"ajax_form", "callback-method"=>"coAuthorformCallback"} , url: desktop_co_authors_path do |f| %> <%= render partial: 'desktop/co_authors/form', locals: {:f => f} %> <% end %> diff --git a/app/views/desktop/journal_pages/_form.html.erb b/app/views/desktop/journal_pages/_form.html.erb index 3d44ec8f..223bea04 100644 --- a/app/views/desktop/journal_pages/_form.html.erb +++ b/app/views/desktop/journal_pages/_form.html.erb @@ -1,13 +1,3 @@ -<% if @writing_journal.errors.any? %> -
-

<%= pluralize(@writing_journal.errors.count, "error") %> prohibited this user from being saved:

- -
-<% end %>
<%= f.submit "Save", name: "commit", value: "Save", class: "fn_btn hh2 thmc2 thmtxt" %>