0
votes

I am new to Ruby and am getting the below error when clicking a link in my app that should render a form used to create a user profile. I really appreciate any help with this.

Missing template profiles/new, application/new with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder, :coffee]}. Searched in: * "/home/ubuntu/workspace/app/views" * "/usr/local/rvm/gems/ruby-2.3.0/gems/devise-3.4.1/app/views"

models/profile.rb

class Profile < ActiveRecord::Base
  belongs_to :user
end

controllers/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

app/views/profiles/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>

config/locales/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
3
Looks like the error is coming from devise? If so, you need to follow the readme for devise gem on how to set up devise properly. - trueinViso
Show your routes, please - Adriano Godoy
Sorry. Routes added. @trueinViso: It is because of devise? - Dean Friedland
Yes, for example the controller needs to inherit from devise, you need views in the devise folder. More info here: github.com/plataformatec/devise/wiki - trueinViso
I tried re-installing but it did not work. And the other forms I have created in the app using Devise have worked fine by the way. Does anyone else have some advice? - Dean Friedland

3 Answers

1
votes

First, no need to include your controller inside a folder

controllers/users/profiles_controller.rb

unless you are using namespace

Whenever you do that, you should namespace your routes like this

namespace :users do
  resources :profiles
end

and your controller will be like this

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

That's how to use a namespace.

Now on your problem, try first to moved the profiles_controller.rb to upto controller folder like this

controllers/profiles_controller.rb

1
votes

I probably deserve a beating for this but the reason for the error was that my view/profiles folder was incorrectly typed as "profliles"! I corrected it and the page is rendering fine now. Thank you for all your help on this. I am going to go put my head in the sand now....

0
votes

Move profiles/new.html.erb under the users folder. Make it app/views/users/profiles/new.html.erb

Or

move controller out of users namespace