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

Friendly urls are not generated on save #485

Open
imunteanu opened this issue Apr 25, 2018 · 8 comments
Open

Friendly urls are not generated on save #485

imunteanu opened this issue Apr 25, 2018 · 8 comments
Assignees

Comments

@imunteanu
Copy link

imunteanu commented Apr 25, 2018

Hi,

It seems that post's slug is not generated when save/update.

I'm using
gem 'refinerycms', '~> 4.0'
gem 'refinerycms-blog', git: 'https://github.com/refinery/refinerycms-blog', branch: 'master'

It might be that this one returns always false:

  # If custom_url or title changes tell friendly_id to regenerate slug when
  # saving record
  def should_generate_new_friendly_id?
    saved_change_to_attribute?(:custom_url) || saved_change_to_attribute?(:title)
  end

I had forced this method to always return false and the slug/friendly_id is generated. So it might be that those attributes are not seen as saved.

I have changed to
attribute_changed?(:custom_url) || attribute_changed?(:title)

and it returns correctly the state of attribute changes. I wonder if is not a Rails 5.1 issue?

thank you
Ionut

@parndt
Copy link
Member

parndt commented Apr 25, 2018

I found some documentation around this: http://blog.toshima.ru/2017/04/06/saved-change-to-attribute.html which says that attribute_changed? is deprecated and that saved_change_to_attribute? is the new version.

We updated this in #480 as this version of Refinery specifically targets Rails 5.1.x

I wonder what could be going wrong?

@imunteanu
Copy link
Author

imunteanu commented May 1, 2018

Sorry for my late response.
It might have been that the documentation of saved_change_to_attribute? was not clear. I would guess that in our case we were evaluating if an attribute was updated, but there was not any save method called yet. (in Rails 5.1+?)

I have changed with will_save_change_to_attribute - post.rb - and it seems to be working fine:
will_save_change_to_attribute?(:custom_url) || will_save_change_to_attribute?(:title)

Couldn't run tests and didn't had time to figure out how can setup al refinerycms in dev mode. If you have some documentation about what do I need setup in a dev env, I will be happy to contribute.

Best
Ionut

@parndt
Copy link
Member

parndt commented May 2, 2018

Hi Ionut, thank you! Does this guide help you? https://www.refinerycms.com/guides/contributing-to-refinery

@imunteanu
Copy link
Author

Yes, I should have seen it :)

I'll make a PR on this issue after I will have the dev + test mode running.

Best
Ionut

@spotlessicode
Copy link

spotlessicode commented Jul 8, 2018

Hi, this little change solved friendly URL me too.

saved_change_to_attribute?(:custom_url) || saved_change_to_attribute?(:title)

to

will_save_change_to_attribute?(:custom_url) || will_save_change_to_attribute?(:title)

@bricesanchez
Copy link
Member

Hi @spotlessicode, could you provide a pull request with a test?

@bricesanchez bricesanchez self-assigned this Jul 9, 2018
@spotlessicode
Copy link

spotlessicode commented Jul 9, 2018

Hi @bricesanchez I tried, but after several hours, I couldn't set forked and cloned refinerycms-blog in local.
screen shot 2018-07-09 at 17 08 08
screen shot 2018-07-09 at 17 07 01

@spotlessicode
Copy link

It doesn' work if you change something in the post, but not the title, it just goes back to the blog/post/1 url instead of the friendly one. So you have to add a space or something at the and of the title if you edit a post and save with that title changes. so better to use body as well:

will_save_change_to_attribute?(:custom_url) || will_save_change_to_attribute?(:title) || will_save_change_to_attribute?(:body)

brigriffin added a commit to brigriffin/refinerycms-blog that referenced this issue Mar 22, 2019
anitagraham pushed a commit to anitagraham/refinerycms-blog that referenced this issue May 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants