Jump to content

Ruby on Rails database problem?

Go to solution Solved by MartinIAm,

Solved it, this is not a problem with my database at all, but my paths. I instead added profile_path to my _follow.html.erb for my notifications and this fixed it!

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.

profile.rb

class Profile < ApplicationRecord
  belongs_to :user
end

user.rb

class User < ApplicationRecord
  has_one :profile dependent: :destroy
end

profile_controller.rb

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])
  end
  def index
  end
end

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.

Link to comment
https://linustechtips.com/topic/1175691-ruby-on-rails-database-problem/
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×