【发布时间】:2018-02-04 03:40:10
【问题描述】:
当我尝试转到新个人资料的链接时,不断收到此错误消息。每个用户只有一个配置文件,配置文件属于用户。在网上找不到任何解决方案。似乎我所有的文件和代码都写得很好。这是我的代码:
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: 'elonmusk@boringcompany.com' %>
</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
用户.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
【问题讨论】:
-
你意识到错误是
Profile控制器,你的叫Profiles吗?
标签: ruby-on-rails ruby