Hello fellow developers,
I am trying to model a one-to-one association with my devise model and for some reason, I cannot access the edit path for the dependent model. Here is what I mean:
I have a CRUD controller for both a User and Credential model. User is a devise model.
class Credential < ActiveRecord::Base
belongs_to :user
end
class User < ActiveRecord::Base
has_one :credential
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable, :lockable and :timeoutable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me
end
I have a homepage under an action named Home in a controller named Welcome. My routes file is setup like so:
get "welcome/home"
devise_for :users
resources :users
resources :credentials
In the home view, upon creation of a new user, I try to update his credentials using
<% if user_signed_in? %>
<% current_user.build_credential unless current_user.credential %>
<% if current_user.sign_in_count < 5 %>
<%= link_to "update profile", edit_credential_path(current_user.credential) %>
<% end %>
<% end %>
I get an error on the link_to
line saying:
No route matches {:action=>"edit", :controller=>"credentials", :id=>#<Credential id: nil, created_at: nil, updated_at: nil, first_name: nil, last_name: nil, user_id: 3>}
Please help.
Thanks.