I’m working in development env but my database is real data from mysqldump of production database
2.3.3 :003 > pr.save
Query Trace > (irb):3:in `irb_binding’
(7.1ms) BEGIN
Query Trace > (irb):3:in `irb_binding’
PressRelease Exists (11.8ms) SELECT 1 AS one FROM press_releases
WHERE press_releases
.id
!= 2 AND press_releases
.slug
= ‘outskirts-of-love-is-available-now-some-autographed-copies-remain’ LIMIT 1
Query Trace > (irb):3:in `irb_binding’
(6.5ms) ROLLBACK
=> false
Try this:
PressRelease.update_all slug: nil
Then try running your &:save! again.
Walter
Still getting ROLLBACK’s
p = PressRelease.first
p.valid?
p.errors.inspect
What do you see?
Walter
“#<ActiveModel::Errors:0x00557931a9a9e8 @base=#<PressRelease id: 2, publicist: "Alligator Records", headline: "OUTSKIRTS OF LOVE Is Available Now! Some Autograph…", storyline: "Alligator Records News, Blues & More \r\nOUTSKIRTS O…", dateline: "2015-09-23 00:00:00", created_at: "2015-09-23 22:57:00", updated_at: "2019-01-28 01:32:11", image_url: "9.png", storyline_html_tail: nil, user_id: nil, artist_id: nil, venue_name: nil, venue_address: nil, venue_phone: nil, showdate: nil, showtime: nil, showtime_second: nil, poster_type: nil, poster_id: nil, additional_info: nil, venue_country: nil, venue_state: nil, venue_city: nil, genre_id: 1, tour_id: nil, press_release_type: "tour", venue_id: nil, venue_type: nil, venue_address0: nil, postal_code: nil, venue_f_address: nil, venue_postal_code: nil, top_story: nil, slug: nil>, @messages={:poster=>["translation missing: en-US.activerecord.errors.models.press_release.attributes.poster.required"]}, @details={:poster=>[{:error=>:blank}]}>”
Great. Now you have your answer. The poster is required, and not valued, so the save won't work. Figure out why the poster is required, and you will fix your application. To be clear, this has nothing at all to do with FriendlyId.
Walter
Because PressRelease belongs_to :poster
Having this problem on another database When I run errors on a row it says :name is blank but if I check the database I can’t find any rows with null :name field, they all have values
=> #<ActiveModel::Errors:0x0055c65e1b4ef8 @base=#<Picture id: 2, comment: “Henry McCarty”, imageable_id: 1, imageable_type: “Photo”, content_type: nil, created_at: “2018-09-20 02:08:02”, updated_at: “2018-10-25 13:41:24”, name: “Billy_the_Kid_Ferrotype.jpg”, designation: nil, blog_id: nil, caption: “Unretouched original ferrotype of Bonney c. 1880”, details: “Henry McCarty”, copyright_claim: false, source_page: nil, slug: nil>, @messages={:name=>[“translation missing: en-US.activerecord.errors.models.picture.attributes.name.blank”]}, @details={:name=>[{:error=>:blank}]}>
class Picture < ActiveRecord::Base
belongs_to :imageable, polymorphic: true
def truncated_details
truncated_details=details.truncate(1024, omission:'')
end
extend FriendlyId
friendly_id :truncated_details, use: :slugged
validates :name, presence: true
mount_uploader :name, PictureUploader
has_many :person_pictures
has_many :people, through: :person_pictures
has_many :photo_pictures
has_many :photos, through: :photo_pictures
attr_accessor :person_id
attr_accessor :picture_id
def formatted_name
“#{name.thumb}”
end
end
What about the through models in has_many_through relationships where i’ve applied friendly_id to the outside models Should I setup the through models to use friendly_id