RailsCasts Pro episodes are now free!

Learn more or hide this

Ray Cudjoe's Profile

GitHub User: rkcudjoe

Site: http://blog.theartoftraction.com

Comments by Ray Cudjoe

Avatar

Has anyone one tried to build associations, with nested resource with frienly_id and having difficulties, and if so, how did you go about solving it?

ruby
#user model
 User < ActiveRecord::Base
  has_one :user_detail

  extend FriendlyId
  friendly_id :username #not slugged, a model column, created with user!

#user_detail model
 UserDetail < ActiveRecord::Base
  belongs_to :user
  
 validates :user_id, presence:true #not attr_accessible.

 #in routes
 resources :users, :path => ''
 resources :users, :path => '', only: [] do
   resource :user_detail, only: [:edit, :update]
end

I've tried everything I could think of to get post requests to work on edit action for user_detail. I've also tried not nesting the the user_detail, still no cigar!

Avatar

Has anyone tried to build associations with friedly_id and having difficulties, and if so, how do you go about solving it?

ruby
User < ActiveRecord::Base
 has_one :user_detail
extend FriendlyId
  friendly_id :username


UserDetail <<ActiveRecord::Base
 belongs_to :user

Based on that i