All threads / Did I forget to do a migration?

Ask A Question


You’re not receiving notifications from this thread.

Did I forget to do a migration?

Christopher Guller asked in Rails

I have a profile model and controller in Rails, and it works all well and good except when I call profile_path or simply "profile". I try and create:

<%= link_to current_user.profile_path %>

and instead of loading a link to the current user's profile path, I get:

 PG::UndefinedTable: ERROR:  relation "profiles" does not exist
LINE 8:  WHERE a.attrelid = '"profiles"'::regclass

Also, in my schema.rb I have nothing mentioning any to profile or profiles. I'm not sure if this helps, but here are my models and controllers.

class Profile < ApplicationRecord
  belongs_to :user


class User < ApplicationRecord
  has_one :profile dependent: :destroy


class ProfileController < ApplicationController
  skip_before_action :configure_permitted_parameters, only: [:show]
  before_action :authenticate_user!, only: [:index, :follow, :unfollow]
  def show
    @user = User.find(params[:id])
  def index

Also a closer step to my issue is that I'm using a "notifications" gem (literally called that) for my notifications and this is what I have under it.

  # Method name of user profile page path, in User model, default: nil
  self.user_profile_url_method = 'profile'

Also, I think this might be a database problem and can probably be fixed with a simple migration, but I'm not sure what to put in the migration to fix it.

Hey Christopher,

path helpers like profile_path are not methods on the User model. You can use <%= link_to "Profile", profile_path %> in your view to link to a route that matches that name.

The Rails guides would be a good place to read through how they work:

This doesn't (and shouldn't) have anything to do with your database. The error makes it look like that because you were trying to call a method on a database object.

Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 38,558+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.