From 912752d6461f4893596c2090b96a6069706df358 Mon Sep 17 00:00:00 2001 From: huang Date: Fri, 30 Dec 2016 13:54:42 +0800 Subject: [PATCH] =?UTF-8?q?=E9=97=AE=E5=90=A7=E7=BC=96=E8=BE=91=E7=9A=84?= =?UTF-8?q?=E6=97=B6=E5=80=99ajax=E5=B1=80=E9=83=A8=E5=88=B7=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/forums_controller.rb | 5 ++--- app/views/forums/_edit.html.erb | 5 +---- app/views/forums/show.html.erb | 4 +++- app/views/forums/update.js.erb | 1 + 4 files changed, 7 insertions(+), 8 deletions(-) create mode 100644 app/views/forums/update.js.erb diff --git a/app/controllers/forums_controller.rb b/app/controllers/forums_controller.rb index 35f8ee97b..a47d8ee09 100644 --- a/app/controllers/forums_controller.rb +++ b/app/controllers/forums_controller.rb @@ -245,15 +245,14 @@ class ForumsController < ApplicationController # PUT /forums/1.json def update @forum = Forum.find(params[:id]) - respond_to do |format| if @forum.update_attributes(params[:forum]) - format.js {render :text=> true} + format.js format.html { redirect_to @forum, notice: l(:label_forum_update_succ) } format.json { head :no_content } else flash.now[:error] = "#{l :label_forum_update_fail}: #{@forum.errors.full_messages[0]}" - format.js { render :text=> false} + format.js format.html { render action: "edit" } format.json { render json: @forum.errors, status: :unprocessable_entity } end diff --git a/app/views/forums/_edit.html.erb b/app/views/forums/_edit.html.erb index 5e8db19a5..e19068ef1 100644 --- a/app/views/forums/_edit.html.erb +++ b/app/views/forums/_edit.html.erb @@ -5,12 +5,9 @@
- <%= labelled_form_for @forum, :html => {:id => "forum_new"} do |f| %> + <%= labelled_form_for @forum, :html => {:id => "forum_new", :remote => true} do |f| %> <%= render :partial => "forums/form", :locals => {:f => f} %> <% end %> - <%#= form_tag({:controller => 'forums', :action => 'create'}, :method => 'post', :id => "forum_new") do |f| %> - - <%# end %>
diff --git a/app/views/forums/show.html.erb b/app/views/forums/show.html.erb index fcc44196a..d07a42ed5 100644 --- a/app/views/forums/show.html.erb +++ b/app/views/forums/show.html.erb @@ -22,7 +22,9 @@
- <%= render :partial => "memos/my_count_message" %> +
+ <%= render :partial => "memos/my_count_message" %> +
diff --git a/app/views/forums/update.js.erb b/app/views/forums/update.js.erb new file mode 100644 index 000000000..721154202 --- /dev/null +++ b/app/views/forums/update.js.erb @@ -0,0 +1 @@ +$("#my_count_message").html('<%= escape_javascript( render :partial => 'memos/my_count_message') %>'); \ No newline at end of file