-
-
Notifications
You must be signed in to change notification settings - Fork 592
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
Rails 5.1 #816
Rails 5.1 #816
Conversation
Closing and reopening to trigger the build again; it seems to be an intermittent problem with bundler installing rack. |
@lazyatom out of curiosity, what's blocking this PR from being merged? |
@scytherswings aside from the build being troubled with bundle installation issues, I think this could be merged... ... but what actually prompted me to make this branch is that in Rails 5.1, calls to
where If I understand correctly what's going on, this is because the behaviour of To illustrate, here's a simple model: class Thing < ActiveRecord::Base
extend FriendlyId
friendly_id :name, use: :slugged
after_save do
trigger_notification_or_something(thing_url(self))
end
end Let's imagine this posts some notification to a service where we want to include the URL to this record (yes, possibly not the best architecture, but bear with me; the main point is that thing = Thing.first
thing.name # => 'Old name'
thing.name = 'New name'
thing.save After the save, the callback is invoked which generates a URL, and because In Rails 5.1 and earlier, It's likely that the new behaviour is actually what we want; the current implementation of However, even aside from that, because calling default_deprecation_behaviours = ActiveSupport::Deprecation.behavior
ActiveSupport::Deprecation.behavior = ->(message, callstack) {
if Rails::VERSION::MAJOR == 5 && Rails::VERSION::MINOR > 1
raise "Remove friendly_id deprecation silencing patch!"
end
unless callstack.find { |l| l.path =~ /gems\/friendly_id/ } &&
message =~ /The behavior of .* inside of after callbacks will be changing/
default_deprecation_behaviours.each { |b| b.call(message, callstack) }
end
} It could be that nobody else in the world is doing anything in ActiveRecord |
@lazyatom wow thank you for such a well thought out response, I really appreciate it. I had no idea |
The minimum version seems to be 2.2.2, but this change is more consistent with the other exclusions.
Was upgrading and reading around. seems to be We'd have to do (correct me if I'm wrong)
Based on the name changes. |
AFAICT, @choonggg, what we need is Additionally, if FriendlyID wants to retain backwards compatibility, then we need to be sure that the That would make the method definition at friendly_id/lib/friendly_id/base.rb Line 262 in e873122
# Either the friendly_id, or the numeric id cast to a string.
def to_param
if friendly_id_config.routes == :friendly
attribute_changed = if self.respond_to?(: will_save_change_to_attribute?)
will_save_change_to_attribute?(friendly_id_config.query_field)
else
attribute_changed?(friendly_id_config.query_field)
end
if attribute_changed
diff = changes_to_save[friendly_id_config.query_field]
diff.first || diff.second
else
friendly_id.presence.to_param || super
end
else
super
end
end @lazyatom Does that seem correct to you? |
@lazyatom I believe the reason that the The expected user case is probably something like this: def update
if @user.update_attributes(slug: "notvalid")
#...
else
flash[:error] = "Failed update because slug is invalid!"
redirect_to @user
end
end In that case, we want |
Closing this in favour of #862, which includes a patch to the actual library. I've suggested a test that also more concretely demonstrates the issue; I believe the callback behaviour is still broken in Rails 5.1, even if it's fixed in Rails 5.2. |
The library itself seems to work with Rails 5.1, but the build needs a few tweaks.