dimanche 31 mai 2015

ActiveRecord::RecordNotFound / Couldn't find Maker with 'id'=1

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.

Aucun commentaire:

Enregistrer un commentaire