Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<%= 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

>Solution :

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading