defiant defiant - 26 days ago 4
Ruby Question

Rails app tries to GET "/users/logo.png" and shows ActiveRecord::RecordNotFound (Couldn't find User with 'id'=logo) with every submit

So at every submit request my rails server shows it is trying to get the logo and then shows there is no user with

id = logo.png
. Can somebody please help me!

Detailed error message:

Started GET "/users/2" for at 2016-10-02 19:01:18 +0530
Processing by UsersController#show as HTML
Parameters: {"id"=>"2"}
User Load (0.0ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 2 LIMIT 1
User Load (0.5ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 2 LIMIT 1
Rendered users/show.html.erb within layouts/application (1.8ms)
Rendered layouts/_header.html.erb (0.0ms)
Rendered layouts/_sidebar.html.erb (1.0ms)
Completed 200 OK in 130ms (Views: 126.9ms | ActiveRecord: 0.5ms)

Started GET "/users/logo.png" for at 2016-10-02 19:01:18 +0530
Processing by UsersController#show as PNG
Parameters: {"id"=>"logo"}
User Load (1.0ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 0 LIMIT 1
Completed 404 Not Found in 3ms (ActiveRecord: 1.0ms)

ActiveRecord::RecordNotFound (Couldn't find User with 'id'=logo):
app/controllers/users_controller.rb:43:in `show'

Here is my routes file:

Rails.application.routes.draw do
root 'dashboard#show'

get 'signup' => 'users#new'
get 'admins' => 'users#admins_dashboard'
delete 'users' => 'users#destroy'
get '/users/edit/:id' => 'users#edit'
resources :users

get 'login' => 'sessions#new'
post 'login' => 'sessions#create'
delete 'logout' => 'sessions#destroy'

My controller action for users:

def show
@user = User.find(params[:id])

def create
@user =
session[:user_id] =
redirect_to '/'
redirect_to '/signup'

the model for users:

class User < ActiveRecord::Base

def admin?
self.role == 'admin'


This happened due to the way the browser resolves relative urls. When you use a fully qualified url for an image src(eg:, the browser doesn't have to do anything. It just issues a request to that URL. However, when you use relative URLs(without the protocol and domain), the browser has to figure out the full URL to issue the request.

You had <img alt="Brand" src="logo.png" /> in your layout, so the browser used the current context to resolve the full URL for that image. When you were on, the src was resolved to because it used the current path. When you were in the homepage the logo could be found because you were at the root path, so it resolved that src to

One way to solve this is to prepend a slash to the src <img alt="Brand" src="/logo.png" /> forcing the browser to resolve it at the root of your domain. That will only work in your rails app if that image is on the public folder.

If you placed the image inside your assets, it's best to use rails image_tag helper. image_tag("logo.png").