Keep getting this error when I try to go to the link for a new profile. Each user has only one profile and profile belongs to user. Can't find any solutions online. Seems like all my files and code is written properly. Here's my code:
home.html.erb
<%= link_to "Create your profile!", new_user_profile_path(user_id: current_user.id) if user_signed_in? %>
profiles/_form.html.erb
<div class="mdl-grid">
<div class=" mdl-cell mdl-cell--4-col"></div>
<div class="mdl-card mdl-shadow--6dp mdl-cell mdl-cell--4-col">
<div class="mdl-card__title mdl-color--primary mdl-color-text--white">
<h2 class="mdl-card__title-text">Create your profile</h2>
</div>
<div class="mdl-card__supporting-text">
<%= form_for @profile, url: user_profile_path do |f| %>
<div class="mdl-textfield mdl-js-textfield field">
<p>First name</p>
<%= f.text_field :first_name, autofocus: true, class: 'mdl-textfield__input', placeholder: 'Elon' %>
</div>
<div class="mdl-textfield mdl-js-textfield field">
<p>Last name</p>
<%= f.text_field :last_name, autofocus: true, class: 'mdl-textfield__input', placeholder: 'Musk' %>
</div>
<div class="mdl-textfield mdl-js-textfield field">
<p>Contact Email</p>
<%= f.email_field :contact_email, autofocus: true, class: 'mdl-textfield__input', placeholder: '[email protected]' %>
</div>
<div class="mdl-textfield mdl-js-textfield field">
<p>Description</p>
<%= f.text_area :description, autofocus: true, class: 'mdl-textfield__input', placeholder: 'I like self-driving cars, rocket ships, and solar energy! Oh and boring tunnels.' %>
</div>
<br>
<div class="mdl-card__actions mdl-card--border actions">
<%= f.submit "Update Profile", class: 'signupform mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--accent' %>
</div>
<% end %>
</div>
</div>
<div class=" mdl-cell mdl-cell--4-col"></div>
</div>
profiles/new.html.erb
<%= render 'form' %>
profile.rb
class Profile < ActiveRecord::Base
belongs_to :user
end
user.rb
class User < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
has_one :profile
end
profiles_controller.rb
class ProfilesController < ApplicationController
# GET to /users/:user_id/profile/new
def new
# Render blank profile details form
@profile = Profile.new
end
end
routes.rb
resources :users do
resources :profile
end
Profilecontroller, yours is calledProfiles? - Sebastian Palma