I'm using the friendly_id gem to handle slugs in my Rails 4 app. For simplicity's sake, let's say I have two resources, Missions and Tasks. Tasks are nested inside Missions. Both models are using FriendlyId, and the slugs are working fine. Because a Task belongs to a Mission, a Task has a mission_id on it.
I'm running into a problem when I update a Task. Because the mission_id is coming through the parameters as a slug (a friendly_id string and not an integer id), the mission_id on the Task is being updated as 0, because it's expecting an integer and is being passed a string.
Anyone have any ideas on how to address this?
routes.rb
resources :missions do
resources :tasks
end
Mission.rb
class Mission < ActiveRecord::Base
extend FriendlyId
friendly_id :name, use: :slugged
has_many :tasks
end
Task.rb
class Task < ActiveRecord::Base
extend FriendlyId
friendly_id :name, use: :slugged
belongs_to :mission
end