我是Ruby的新手,在点击我的应用中应该呈现用于创建用户个人资料的表单的链接时,我收到以下错误。我真的很感激任何帮助。
缺少模板配置文件/ new,application / new with {:locale => [:en],:formats => [:html],:variants => [],:handlers => [:erb ,:builder,:raw,:ruby,:jbuilder,:coffee]}。搜索:*" / home / ubuntu / workspace / app / views" *" /usr/local/rvm/gems/ruby-2.3.0/gems/devise-3.4.1/app/views"
模型/ profile.rb
class Profile < ActiveRecord::Base
belongs_to :user
end
控制器/ profiles_controller.rb
class ProfilesController < ApplicationController
def new
# form where a user can fill out their own profile.
@user = User.find( params[:user_id] )
@profile = @user.build_profile
end
end
应用/视图/简档/ new.html.erb
<div class="row">
<div class="col-md-6 col-md-offset-3">
<h1 class="text-center">Create Your Profile</h1>
<p class="text-center">Be a part of the Dev Match community and fill out your profile!</p>
<div class="well">
<%= form_for @profile, url: user_profile_path do |f| %>
<div class="form-group">
<%= f.label :first_name %>
<%= f.text_field :first_name, class: 'form-control' %>
</div>
<div class="form-group">
<%= f.label :last_name %>
<%= f.text_field :last_name, class: 'form-control' %>
</div>
<div class="form-group">
<%= f.label :job_title %>
<%= f.select :job_title, ['Developer', 'Entrepreneur', 'Investor'], {}, class: 'form-control' %>
</div>
<div class="form-group">
<%= f.label :phone_number %>
<%= f.text_field :phone_number, class: 'form-control' %>
</div>
<div class="form-group">
<%= f.label :contact_email %>
<%= f.text_field :contact_email, class: 'form-control' %>
</div>
<div class="form-group">
<%= f.label :description %>
<%= f.text_area :description, class: 'form-control' %>
</div>
<div class="form-group">
<%= f.submit "Update Profile", class: 'btn btn-primary' %>
</div>
<% end %>
</div>
配置/区域设置/ routes.rb中
Rails.application.routes.draw do
devise_for :users, controllers: { registrations: 'users/registrations' }
resources :users do
resource :profile
end
resources :contacts
get '/about' => 'pages#about'
root 'pages#home'
end
答案 0 :(得分:1)
首先,无需将控制器包含在文件夹
中<强>控制器/用户/ profiles_controller.rb 强>
除非您使用名称空间
每当你这样做时,你应该像这样命名你的路线
namespace :users do
resources :profiles
end
你的控制器将是这样的
class Users::ProfilesController < ApplicationController
def new
# form where a user can fill out their own profile.
@user = User.find( params[:user_id] )
@profile = @user.build_profile
end
end
这是如何使用命名空间。
现在问题,请先尝试将profiles_controller.rb移动到这样的控制器文件夹
<强>控制器/ profiles_controller.rb 强>
答案 1 :(得分:1)
我可能应该为此受到打击,但错误的原因是我的view / profiles文件夹被错误地键入为&#34; profliles&#34;!我纠正了它,现在页面渲染得很好。感谢您对此的所有帮助。我现在要把头埋在沙子里......
答案 2 :(得分:0)
在profiles文件夹下移动profiles / new.html.erb。将其设为app / views / users / profiles / new.html.erb
或
将控制器移出用户名称空间