P
P
Philipp2014-09-19 22:38:33
Ruby on Rails
Philipp, 2014-09-19 22:38:33

How to properly route in Rails?

The task is a bit trivial, but so far I don't know Ruby & Rails well.
In general, a site for photo studios is planned. Each has photos and possibly sections inside.
The next CNC is planned
/:company/:photo/
or
/:company/:category/:photo
I understand that you need to somehow arrange the nested resources and segments .
Plus, you need to somehow fit this all into the fact that photos are uploaded by photographers who can work with several studios (which I did not expect at all). It turns out that having gone inside the studio, they can upload the photo immediately to this studio without any questions. I think it can somehow be done using 2 different rules.
And now the most unpleasant moment - companies and categories can 100% have human aliases and here lies the snag - how to combine id & alias. The only thing is the creation of a constraint, which will understand that only numbers are transferred and this can be considered an id, and if letters, then an alias.
It is not clear how such /ooo-romashka/23/17 will work .
This is how I imagine the beginning

get '/:id', to: 'company#show', constraints: { id: /^\d.+$/ }
get '/:alias', to: 'company#show'

But it's read-only. How to make a full-fledged RESTfull?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Viktor Vsk, 2014-09-19
@viktorvsk

resources :company do
member do
# /company/50/:photos
resources :photos
end
collection do
get :category, to: "category#index"
end
end

A full-fledged restfull is resources. And you can invest in resources a member (what is hung on a specific resource) and a collection (what is on the entire resource). What is meant by categories, I did not quite understand, so the example is abstract.

V
vsuhachev, 2014-09-20
@vsuhachev

If /:company/:photo/ and /:company/:category/:photo refer to the same photo, it is no longer restful. Yes, and search engines do not recommend giving one page to different URLs. If
I were you, I would do something like this:
/studies/ooo-romashka
/studies/ooo-romashka/categories/svadebnaya-siemka
/studies/ooo-romashka/photos/ 155
/studies/ooo-romashka/photos/?category=svadebnaya-siemka
/authors/ivanov-ivan-ivanovich/photos/?category=svadebnaya-siemka
For aliases, look at this gem , maybe it will suit you

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question