Home > Net >  How can I route/reference one to one relationship in Ruby on Rails
How can I route/reference one to one relationship in Ruby on Rails

Time:11-12

Sorry, I am very new to Ruby on Rails, a bit confused on how to route tables with one to one ralationshipts

I have two models, User and Userdetail

class User < ApplicationRecord
  has_one :userdetail
end

class Userdetail< ApplicationRecord
    belongs_to :user
end

In my application.html.erb I am trying to add a link for a user to go to user details, something like that

<%= link_to 'User Information', userdetail_path %>

How can I make this link to work, what should I place in my routes.rb file to reference one to one relationshipt of User and Userdetail

Thank you very much in advance

CodePudding user response:

You don't need to reference the one-to-one relationship to get a userdetail_path helper. In your routes.rb, make sure you have this:

resource :userdetail, only: :show
  • Related