Keep getting routing error on pin_image - ruby-on-rails

I'm a newbie to coding and have been using SO to look for this answer. People have the same error but I can't figure out how it relates to my problem.
I'm working on a Pinterest clone but I keep getting this error in the command line when I add pictures. ActionController::RoutingError (No route matches [GET] "/pin_images/original/missing.png"):
How would I add it to the routes? I thought it would already be allowed
Rails.application.routes.draw do
resources :pins
devise_for :users
root 'home#index'
get 'new/pins'
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end

Related

Rails routes appear but throws a 404 error

I'm trying to thrown a 404 error without redirect for unknown routes. It works correctly but when I go to the show routes, that it is in the rails routes, it throws a 404 too.
Relevant section from routes.rb
get '(/:department)', to: 'products#index'
get 'saldao', to: 'products#on_sale', as: :on_sale
get '*missing', to: 'error#error_404', as: :error_404
get '(:department)(/:brand)(/:os)', to: 'products#index', as: :products
get '(:department)(/:brand)(/:os)/:slug', to: 'products#show', as: :product
It`s weird because Product#show appears in the routes when i check:
products GET (/:scope)(/:department)(/:brand)(/:os)(.:format) frontend/products#index {:scope=>/pre|loyalty|corporativo|diaconsumidor|troca4g|troca3g4g|outlet|j4|z3|j6/, :department=>/celulares|acessorios|pos|controle|wttx/, :brand=>/alcatel|apple|asus|lenovo|lg|motorola|nokia|philips|positivo|samsung|sony|tim|wnc/, :os=>/android|ios|windows-phone/}
I've tried a lot of things and haven`t been succesfull.
The error route also stops work with I move it to the end of file.

Creating custom routes in Rails for SEO

I am following a tutorial on seo in rails and i got my routes.rb like this
resources :blogs,only: [:new,:index]
get "/blogs/:id", to: redirect("/%{id}")
resources :blogs,:path=>'',except:[:new,:index]
everything should be fine but when i create a blog it doesn't show error and doesn't create a blog too.it just redirects to blogs_path.
what am i doing wrong?
it works fine like
resources :blogs
but then i would lose the benefits of the other code. and i need them for my SEO.
after a day of sleeping on it I found that i had to mention the :create and :update actions to my routes it'll be like this
resources :blogs,only: [:new,:index,:create,:update]
get "/blogs/:id", to: redirect("/%{id}")
resources :blogs,:path=>'',except:[:new,:index]

How to stop Rails route preempting another

I am working on an API for a mobile app. I am running into a problem where one of my routes is preempting another. The two routes are:
api_vocabs_all GET /api/vocabs/all(.:format) api/vocabs#all
api_vocab GET /api/vocabs/:id(.:format) api/vocabs#show
Whenever I navigate to "api/vocabs/all" Rails sends the request to the show method with the id = all. Is there a way around this?
Update: Looking at my code again I noticed that while the above doesn't work the non-api version does work. Do I need to put my route inside the namespace?
vocabs_all GET /vocabs/all(.:format) vocabs#all
vocab GET /vocabs/:id(.:format) vocabs#show
Below are all my routes from routes.rb
namespace :api do
resources :vocabs
end
get 'vocabs/all' => 'vocabs#all'
get 'api/vocabs/all' => 'api/vocabs#all'
resources :vocabs
Converting my comment into an answer. Put api/vocabs/all above the namespace :api. Remember that your routing file should be ordered from most specific to least specific.
get 'api/vocabs/all' => 'api/vocabs#all'
namespace :api do
resources :vocabs
end
get 'vocabs/all' => 'vocabs#all'
resources :vocabs

Changing the route from posts/article to blog/article in rails

I'm in trouble with routes in Rails. I've been trying to get a path like: home/blog/title-article but the closes I get is: home/blog/posts/title-article
I've tried with namespace, scope and one by one with get 'blog' => 'posts#blablabla', but I get errors like UrlGenerationError or NameError every time I change the paths. I've read the official guide and some answers in this forum, but I'm getting more confused hehe
In my last try I generated a controller Blog and a scaffold Post. The output of rake routes is: http://i.stack.imgur.com/gdfPc.png
routes.rb
Rails.application.routes.draw do
scope :blog do
resources :posts
end
get 'blog' => 'blog#index'
root 'pages#index'
...
Thank you!
Now my routes are like: http://i.stack.imgur.com/cKsFG.png
Thank you!
Not sure its what you expect but try:
resources :posts, path: 'blog'
Feels weird though.
Btw, I guess you have the errors due to url helpers.
use rake routes to check the existing routes and the related url helpers.
Doc lives here

Getting no route matches on the show action

I'm trying to use the path from the following route, here is what it's like in rake routes
chapter GET /chapters/:id(.:format) {:action=>"show", :controller=>"chapters"}
chapter_path creates a link to /chapters/x which is correct but I get the routing error when trying to access it.
No route matches {:controller=>"chapters"}`
this is my routes (I am using shallow routing to create a books_chapters and book_chapters_new paths.
resources :books do
resources :chapters, :shallow => true
end
when I test the route with rake routes, I get books_chapters, books_chapters_new, chapters and books, so I don't know what's wrong.
when i remove :shallow => true, i can access /books/1/chapters/6 but I just want it to be /chapters/6
this is what my terminal looks like
so /chapters/id and /chapters/id/edit should be working fine.
I've restarted the server with touch tmp/restart.txt and ran rails s to see if the routes worked there too and rake routes is giving me acceptable routes, but they don't work for me.
Are you supplying the parameter for the path helper, something like
chapter_path(#chapter)
I couldn't figure out how to get :shallow routes to work, and there isn't an example on how to use :shallow in the rails guide so, instead I have to just use nested routes like so
resources :books do
resources :chapters
end
now this means the something like chapters_url or chapters_path won't work.
So I have to do something like this everywhere
book_chapter_url(#chapter.book, #chapter)
or
edit_book_chapter_path(#chapter.book, #chapter)
It works but there's a bit of code smell because I use #chapter twice and the whole url should be able to resolve just through the chapter id instead.

Resources