M
M
Michael Lenis2013-11-20 23:40:46
Ruby on Rails
Michael Lenis, 2013-11-20 23:40:46

How to create unique subpages in ROR posts?

Rails 4.0.1
Ruby 2.0.0p247
I don't use the admin panel.
Challenge:
Creating a subpage in a specific post?
Legend:
1) Create a new entry Animals under the name "animals." I enter the data "Title", "Description", save.
2) The page is available at www.foo.ru/bar/animals.
It is necessary that when creating the record "Animals" it was possible to create the pages of the view, Photos, Views, Countries. Which would be available at www.foo.ru/bar/animals/photo, etc.
Moreover, for each record, its own pages are created.
Tell me how this can be implemented?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
anathem, 2013-11-21
@anathem

If I understand correctly (and not a fact), then:
a) take Photos, Views, etc. separate models, in the routes to prescribe something like:

resources :animals do
   resources :photos
   ...
end

in the animal model - has_many :photos and photo - belongs_to :animal
When creating, just use nested resources and get something like .../animals/1/photos .
b) Catch dynamic action in routes and make a route on it. In the routes, something like:
get '*actions' => 'animals#mega_action'
But it will be a strange option :)
If this is not what was meant, then you can clarify a little more :)

O
Oleg S, 2013-11-21
@qazwsx

You can make a Page model and routes

resources :animals do
  member do
    get ":page" => "pages#show"
  end
end

I solved a similar problem using constraints like this:
scope '/animals/:id/:page', :constraints => PageConstraint 
  get '' => 'pages#show'
end

Constraint to check if there is such a page or not.

A
Adil1, 2013-11-26
@Adil1

http://railscasts.com/episodes/403-dynamic-forms should help if the question is still relevant, you can download it from rutracker

B
Boris Penkovsky, 2013-12-22
@Able1991

get 'pages/:parent_page/'
get 'pages/:parent_page/:children_page'
get 'pages/:parent_page/:children_page/:children_children_page'

not?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question