Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Edit this post" link on sitebar #445

Open
duarme opened this issue Jun 19, 2015 · 3 comments
Open

"Edit this post" link on sitebar #445

duarme opened this issue Jun 19, 2015 · 3 comments

Comments

@duarme
Copy link
Contributor

duarme commented Jun 19, 2015

It would be nice if this feature would also work for the blog posts.

@duarme duarme changed the title Edit current post link on sitebar "Edit this post" link on sitebar Jun 19, 2015
@duarme
Copy link
Contributor Author

duarme commented Jun 19, 2015

I'd like to develop it if that's ok with you.
In order to make it work I think that refinerycms-blog should somehow override the Refinery::SiteBarHelper. Am I right?

@evenreven
Copy link

evenreven commented Sep 19, 2019

It's been four years, so possibly not of interest to anyone (least of all @darmenise ), but Google took me here, so... :)

My project's editors wanted an "edit this page" for our events (which uses a heavily customised extension that began with this guide), and since it's a different model from pages, I had to find my own solution. It's not exactly elegant, but it works.

  1. First, override the helper site_bar_helper.rb (put it in app/helpers/refinery). I can't remember if I did this with an override command, or if I manually put it there. Probably this command: bin/rails refinery:override helper=refinery/site_bar (maybe it needs the full file name, can't remember).
  2. Then override the view partial _site_bar.html.erb with this command: bin/rails refinery:override view=refinery/_site_bar (or I put it in app/views/refinery manually, can't remember).

Then I made this change:

diff --git a/app/helpers/refinery/site_bar_helper.rb b/app/helpers/refinery/site_bar_helper.rb
index 6d65199..3cd6ec7 100644
--- a/app/helpers/refinery/site_bar_helper.rb
+++ b/app/helpers/refinery/site_bar_helper.rb
@@ -12,11 +12,18 @@ module Refinery
     end
 
     def site_bar_edit_link
-      return nil if admin? || @page.nil?
-      link_to t('refinery.admin.pages.edit', site_bar_translate_locale_args),
-              refinery.admin_edit_page_path(@page.nested_url,
-              :switch_locale => (@page.translations.first.locale unless @page.translated_to_default_locale?)),
-              'data-turbolinks' => false
+      if model = @page
+        return nil if admin? || @page.nil?
+        link_to t('refinery.admin.pages.edit', site_bar_translate_locale_args),
+                refinery.admin_edit_page_path(@page.nested_url,
+                :switch_locale => (@page.translations.first.locale unless @page.translated_to_default_locale?)),
+                'data-turbolinks' => false
+      elsif model = @event
+        return nil if admin? || @event.nil?
+        link_to t('refinery.admin.pages.edit', site_bar_translate_locale_args),
+                "#{Refinery::Core.backend_path}/events/#{@event.id}/edit?switch_locale=#{locale}",
+                'data-turbolinks' => false
+      end
     end
 
     def site_bar_translate_locale_args

I couldn't find a handy method like admin_edit_page_path to link directly to the event, so I made my own URL with a combination of methods and static strings. The last #{locale} is defined in my app's locale picker code, so it likely won't work for anyone else (I think it's a self-defined alias for some other longer method name involving I18n or Globalize in some way), but it's only needed because my events don't use title in URL (aka pretty URLs) but event IDs (like /events/987).

It's probably not the most elegant method, but the if model = @page conditionals has helped me in other parts of the app as well. E.g. the locale picker wouldn't work without it, since I needed fallback content to be treated differently on different models.

This isn't a solution to this issue, but it might be a starting point for some devs who use the blog extension. Hope it helps some future Googler! :)

@duarme
Copy link
Contributor Author

duarme commented Sep 19, 2019

Eh eh, thank you anyway! 👍 it will surely help someone else :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants