B
B
Boober2015-01-23 20:42:53
Ruby on Rails
Boober, 2015-01-23 20:42:53

How to remap model paths in Rails?

Hello, I have models, but Rails incorrectly defines the paths for them (i.e. you have to write form_for(@model, url: my_new_url_path) . So I would like to define this in the model one day and not write the url:
Is it possible to do this?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Viktor Vsk, 2015-01-23
@viktorvsk

Usually, if a computer incorrectly determines something, then it is being used for other purposes. It is especially easy to make such a mistake in such a "conventional" environment as rails.
What do you mean it misidentifies?
Are you making a link like
/users/username instead of /users/id ?
Then there is the to_param method

J
Jeiwan, 2015-01-23
@Jeiwan

To correctly generate paths for nested resources, in form_for you need to pass an array as the first parameter: you
get article_comment_path or '/article/:article_id/comment/:id'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question