Slugging breaks through a has_many #284

Closed
matthewrudy opened this Issue May 15, 2012 · 3 comments

Comments

Projects
None yet
2 participants

I have the following setup

class User
  has_many :items
end

class Item
  belongs_to :user

  extend FriendlyId
  friendly_id :name, :use => :slugged
end

Everything works find working with an Item directly, but when its created through user.items things go wrong

Item.new(:name => "Some Name", :user_id => 1).save!
# works

user.items.build(:name => "Some Name").save!
# doesnt set the slug, and breaks on NOT NULL constraint

Further interrogation reveals

Item.new.send(:set_slug) # works

User.first.items.build.send(:set_slug)
# NoMethodError: undefined method `set_slug' for #<Item:0x007fefd94cd0d0>

Update: I tried adding a test to the project [https://github.com/matthewrudy/friendly_id/commit/7ba6821ffc835430140d6717e1c4d7af8e4b854a] and it works.

I guess this is some subtle thing to do with rails development mode.

Collaborator

xymbol commented Dec 8, 2012

@matthewrudy Can you confirm this issue is still valid? I couldn't find your test code.

i think this was an obscure one off issue.
so let's just close it.
thanks.

matthewrudy closed this Dec 9, 2012

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