From dfe9065916c27cbf2de7bfc26c9534a65a4369fa Mon Sep 17 00:00:00 2001 From: manson Date: Tue, 5 Aug 2014 14:45:30 +0800 Subject: [PATCH] Add link_to_edit for frontend --- .../admin/page_contents_controller.rb | 6 +++--- app/controllers/page_contents_controller.rb | 16 +++++++++------- app/views/admin/page_contents/new.html.erb | 1 + app/views/page_contents/index.html.erb | 6 +++++- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/app/controllers/admin/page_contents_controller.rb b/app/controllers/admin/page_contents_controller.rb index 8465347..800f963 100644 --- a/app/controllers/admin/page_contents_controller.rb +++ b/app/controllers/admin/page_contents_controller.rb @@ -18,10 +18,10 @@ class Admin::PageContentsController < OrbitAdminController end def create - @page_content = PageContext.new(update_params) + @page_content = PageContext.new(update_params) @page_content.update_user_id = current_user.id - @page_content.save - redirect_to admin_page_contents_path + @page_content.save + redirect_to params['referer_url'] end def view diff --git a/app/controllers/page_contents_controller.rb b/app/controllers/page_contents_controller.rb index 1c35de9..434a9f7 100644 --- a/app/controllers/page_contents_controller.rb +++ b/app/controllers/page_contents_controller.rb @@ -1,9 +1,11 @@ class PageContentsController < OrbitAdminController - def index - params = OrbitHelper.params - page = Page.where(:page_id => params[:page_id]).first - { - "html" => (page.page_contexts.last.content rescue "") - } - end + def index + params = OrbitHelper.params + page = Page.where(:page_id => params[:page_id]).first + url_to_edit = OrbitHelper.user_can_edit?(page) ? "/admin/page_contents/new?page_id=#{page.id.to_s}" : "" + { + "html" => (page.page_contexts.last.content rescue ""), + "url_to_edit" => url_to_edit + } + end end \ No newline at end of file diff --git a/app/views/admin/page_contents/new.html.erb b/app/views/admin/page_contents/new.html.erb index 35fcced..3c58621 100644 --- a/app/views/admin/page_contents/new.html.erb +++ b/app/views/admin/page_contents/new.html.erb @@ -33,6 +33,7 @@
<%= f.hidden_field :page_id, :value=>@page.id.to_s %> <%= f.hidden_field :version, :value=>((@page.page_contexts.last.version + 1) rescue 1)%> + <%= f.submit t("save"), :class=> "btn btn-primary bt-form-save" %>
diff --git a/app/views/page_contents/index.html.erb b/app/views/page_contents/index.html.erb index 0fe3ce0..1fdd26a 100644 --- a/app/views/page_contents/index.html.erb +++ b/app/views/page_contents/index.html.erb @@ -1,2 +1,6 @@ <% data = action_data %> -<%= data["html"].html_safe %> \ No newline at end of file +<%= data["html"].html_safe %> + +<% if !data["url_to_edit"].blank? %> +

<%= t(:edit) %>

+<% end %> \ No newline at end of file