S
S
Stan_12016-02-24 01:45:15
Ruby on Rails
Stan_1, 2016-02-24 01:45:15

How to dynamically change routing in Rails?

Goodnight!
Today half a day I was steaming over one task, but I have no solution yet. Let's say I created a FAQ page. To do this, I created a FaqController controller, and configured the routing: get '/faq', to: "faq#index".
All is well, until the moment the user wants to change the name for SEO and make "host.com/voprosy-i-answer". And the task is to do this without changing the routing files.
I see three ways to do this, I tried two, the third did not have time. But maybe I'm missing something fundamentally?
1. I catch the "Page not found" error. I check the "mapping" database, that is, I see that the voprosu-i-answer page matches the old Faq, and I call FaqController via render. Problem: when rendering, action
2 is not called.. Error - controller does not contain actions. When I look at the controller created in this way through .inspect, I see that it is "empty" - there is nothing in it. :(
3. Change routing on the fly, approximately, as described here . But it looks like a hard life hack.
Maybe there is a better way to solve such a problem?
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
N. Bekseitov, 2016-02-24
@Stan_1

Why not just create a pages model with a url_name attribute to hold the faq. Well, then use the friendly_id gem.

T
TyzhSysAdmin, 2016-02-24
@POS_troi

I certainly don't doubt your good intentions, but since when did rail projects become "All is well, until the moment the user wants to change" ?
Rails are such a thing that those who come to them are definitely able to get into the route and bring it to the state it needs :)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question