0
votes

I might've erased my user information (:maker_id, :name, and :password) when I did rake db:reset in terminal, so now going to 'localhost:3000' '/' gives me this error:

ActiveRecord::RecordNotFound in PagesController#home

Couldn't find Maker with 'id'=1

Extracted source (around line #7):

6 def current_user

7 @current_user ||= Maker.find(session[:maker_id]) if session[:maker_id]

8 end

9 helper_method :current_user

My application controller has:

class ApplicationController < ActionController::Base

  protect_from_forgery with: :exception

  def current_user
    @current_user ||= Maker.find(session[:maker_id]) if session[:maker_id]
  end
  helper_method :current_user

  def authorize
    redirect_to '/' unless current_user
  end

end

My pages controller has an empty

def home
end

My pages home.html.erb view has:

<div class='text-center'>
    <h1>Welcome to venture</h1>

    <br><br>

    <%= link_to "Signup", '/signup', class: 'btn btn-success' %> or
    <%= link_to "Login", '/login', class: 'btn btn-primary' %>
</div>

My layouts application.html.erb view has:

<body class="containter">

  <div class='pull-right'>
    <% if current_user %>
      Logged in as <%= current_user.name %> | <%= link_to "Logout", '/logout' %>
    <% else %>
      <%= link_to "Signup", '/signup'%> or <%= link_to "Login", '/login' %>
    <% end %>
  </div>

  <h1><%= link_to 'venture', '/' %></h1>

  <% flash.each do |type, message| %>
    <div class="alert alert-info fade in">
      <button class="close" data-dismiss="alert">×</button>
      <%= message %>
    </div>
  <% end %>

<%= yield %>

</body>

It used to work before the db:reset which runs db:drop db:setup I believe. Usually I would just create users through the signup page but now I cannot get there.

Any insight is appreciated.

2

2 Answers

1
votes

These records are not available any more - when db:drop was executed, all of them have been removed. The operation can not be undone and at the moment the only options you have is to restore db either manually or automatically if you have access to its backup.

0
votes

Run rake db:setup to recreate your database. Then create a new user.

Checkout this answer to see the differences between various rake db commands