Aaron Eveleth
Aaron Eveleth

Reputation: 117

Rails Custom Routes Changes Assets Paths Resulting In 404 For Assets

I'm trying to customize my routes like this: get 'lcd-buyback/lot/:id' => 'lcd_buyback#lot_view'

I originally had it like this: get 'lcd_buyback/lot_view' => 'lcd_buyback#lot_view'

The issue is that when I use the custom route, I get a 404 for my assets.

Here is the Request URL that gives 404: http://localhost:3000/lcd-buyback/bootstrap/dist/css/bootstrap.min.css

Here is the Request URL that doesn't: http://localhost:3000/bootstrap/dist/css/bootstrap.min.css

As you can see, the custom route adds the lcd-buyback path I specified, to the assets Request URL.

How can I successfully access my assets when I customize routes? Thanks

Upvotes: 0

Views: 386

Answers (1)

user7653331
user7653331

Reputation:

Assets are called from your layout file with the corresponding tag. Make sure your lcd_buyback controller is using the right layout file.

In app/views/application.html.erb you will find:

<%= stylesheet_link_tag 'application' %>

In app/assets/stylesheets/application.css you will find the file and all the other stylesheets it imports, as this example:

 *= require_self
 *= require bootstrap
 *= require tree .

On the first url you are missing /lot in order to match the new route.

Please provide more information about your controller and routes file.

Upvotes: 1

Related Questions