From abbe1e86ac2a6c171e309c1218724e2dd63d76a6 Mon Sep 17 00:00:00 2001 From: Rueshyna Date: Wed, 5 Dec 2012 17:49:41 +0800 Subject: [PATCH] make coauthor relation can be edit --- .../desktop/co_author_relations_controller.rb | 15 +++++++++++++++ .../desktop/co_author_relations/_form.html.erb | 6 ++---- .../desktop/co_author_relations/_new.html.erb | 3 +++ .../co_author_relations/_show_form.html.erb | 1 + .../desktop/co_author_relations/edit.html.erb | 3 +++ .../desktop/co_author_relations/index.html.erb | 2 +- app/views/desktop/co_authors/edit.html.erb | 2 +- app/views/desktop/co_authors/new.html.erb | 2 +- 8 files changed, 27 insertions(+), 7 deletions(-) create mode 100644 app/views/desktop/co_author_relations/_new.html.erb create mode 100644 app/views/desktop/co_author_relations/edit.html.erb diff --git a/app/controllers/desktop/co_author_relations_controller.rb b/app/controllers/desktop/co_author_relations_controller.rb index cb01915e..d5f9d614 100644 --- a/app/controllers/desktop/co_author_relations_controller.rb +++ b/app/controllers/desktop/co_author_relations_controller.rb @@ -8,6 +8,10 @@ class Desktop::CoAuthorRelationsController < ApplicationController end end + def edit + @co_author_relation = CoAuthorRelation.find(params[:id]) + end + def new @new_relation = CoAuthorRelation.new end @@ -25,6 +29,17 @@ class Desktop::CoAuthorRelationsController < ApplicationController end end + def update + @co_author_relation = CoAuthorRelation.find(params[:id]) + + if @co_author_relation.update_attributes(params[:co_author_relation]) + render json: {success:true, msg: t('update.sucess.co_author')}.to_json + else + error_msg = @co_author.errors.full_messages.join("
") + render json: {success: false, msg: error_msg}.to_json + end + end + def destroy @co_author_relation = CoAuthorRelation.find(params[:id]) @co_author_relation.destroy diff --git a/app/views/desktop/co_author_relations/_form.html.erb b/app/views/desktop/co_author_relations/_form.html.erb index a6d2b68e..04ebe5ed 100644 --- a/app/views/desktop/co_author_relations/_form.html.erb +++ b/app/views/desktop/co_author_relations/_form.html.erb @@ -1,4 +1,2 @@ -<%= form_for(@new_relation , url: desktop_co_author_relations_path, html:{"form-type"=>"ajax_form", "callback-method"=>"coauthorRelationForm"} ) do |f| %> - <%= f.text_field :relation %> - <%= f.submit "Save" %> -<% end %> +<%= f.text_field :relation %> +<%= f.submit "Save" %> diff --git a/app/views/desktop/co_author_relations/_new.html.erb b/app/views/desktop/co_author_relations/_new.html.erb new file mode 100644 index 00000000..6e137c88 --- /dev/null +++ b/app/views/desktop/co_author_relations/_new.html.erb @@ -0,0 +1,3 @@ +<%= form_for(@new_relation , url: desktop_co_author_relations_path, html:{"form-type"=>"ajax_form", "callback-method"=>"coauthorRelationForm"} ) do |f| %> + <%= render partial: 'desktop/co_author_relations/form' , locals: {:f => f}%> +<% end %> diff --git a/app/views/desktop/co_author_relations/_show_form.html.erb b/app/views/desktop/co_author_relations/_show_form.html.erb index d3c803d3..36c9728a 100644 --- a/app/views/desktop/co_author_relations/_show_form.html.erb +++ b/app/views/desktop/co_author_relations/_show_form.html.erb @@ -1,6 +1,7 @@ <% @co_author_relations.each do |co_author_relation| %> <%= co_author_relation.relation %> + <%= link_to 'Edit', edit_desktop_co_author_relation_path(co_author_relation), :class => "bt-edit" %> <%= link_to 'Destroy', desktop_co_author_relation_path(co_author_relation), confirm: 'Are you sure?', method: :delete, :class=>"bt-delete" %> <% end %> diff --git a/app/views/desktop/co_author_relations/edit.html.erb b/app/views/desktop/co_author_relations/edit.html.erb new file mode 100644 index 00000000..311536f0 --- /dev/null +++ b/app/views/desktop/co_author_relations/edit.html.erb @@ -0,0 +1,3 @@ +<%= form_for(@co_author_relations, url: desktop_co_author_relation_path(@co_author_relations), html:{"form-type"=>"ajax_form", "callback-method"=>"coauthorRelationForm"} ) do |f| %> + <%= render partial: 'desktop/co_author_relations/form' , locals: {:f => f}%> +<% end %> diff --git a/app/views/desktop/co_author_relations/index.html.erb b/app/views/desktop/co_author_relations/index.html.erb index 157db942..cc37e6a5 100644 --- a/app/views/desktop/co_author_relations/index.html.erb +++ b/app/views/desktop/co_author_relations/index.html.erb @@ -1,7 +1,7 @@

Listing co_author_relations

<%= submit_tag "Back", :type => "button", class: "bt-cancel fn_btn hh2 thmc2 thmtxt" %> -<%= render 'form' %> +<%= render 'new' %> diff --git a/app/views/desktop/co_authors/edit.html.erb b/app/views/desktop/co_authors/edit.html.erb index 015f6321..b2581353 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, html: { multipart: true ,"form-type"=>"ajax_form", "callback-method"=>"coAuthorformCallback"} , url: desktop_co_author_path(@co_author) do |f| %> +<%= form_for @co_author_relation, html: { multipart: true ,"form-type"=>"ajax_form", "callback-method"=>"coAuthorformCallback"} , url: desktop_co_author_path(@co_author_relation) 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 1a4ec2d5..3fd7d2e1 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 ,"form-type"=>"ajax_form", "callback-method"=>"coAuthorformCallback"} , url: desktop_co_authors_path do |f| %> - <%= render partial: 'desktop/co_authors/form', locals: {:f => f} %> + <%= render partial: 'desktop/co_author_relations/form', locals: {:f => f} %> <% end %>