-1

I have two models - Team and Campaign.

Team has_many :campaigns & Campaign belongs_to :team

Using friend_id gem, I have my team routes working as expected i.e https://localhost/t/myteam

However, for campaign_path(@campaign.team, @campaign) my url shows up as http://localhost/t/1/campaign/1 while I am expecting it to be http://localhost/t/myteam/campaign/1

How can I achieve this? What am I doing wrong?

Sharing snippet of my routes code.

resources :teams, :path => 't' do
  member do
    get :new_invite
    resources :campaigns, :path => 'c' do
      member do
        get :share_callback
        get :enter
      end
    end
  end
end

Campaign.rb

extend FriendlyId
friendly_id :campaign_heading, use: :slugged
belongs_to :team

Team.rb

extend FriendlyId
friendly_id :slug, use: :slugged
Vasilisa
  • 4,604
  • 3
  • 20
  • 25
HighOnRails
  • 43
  • 2
  • 7

2 Answers2

0

Try to use it more explicit:

team_campaign_path(team_id: @campaign.team.slug, @campaign)
Vasilisa
  • 4,604
  • 3
  • 20
  • 25
-1

Is the route a resourced route?. If it is, then you need to set the param key to slug. Like this:

resources :campaigns, param: :slug
Ezenwa
  • 80
  • 1
  • 4