-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make object_path/object_url generate path/url matching with the ones defined in Rails routes #1
Comments
It needs some kind of reference to connect a model with the desired Rails route, an object may often have more than one route (or just one unique route). @skalee would you have time to help here? |
I should be able to do this one, and EnMail in parallel. |
@PeterTKY How does it differ from stock Rails' |
They should be quite similar. But I just tested a little bit in my Rails console. The url_for method seems not working in places other than ActionView.
It will result in error:
Unfortunately that's our major use case for object path... |
u = User.create
#=> #<User id: 1, email: nil, created_at: "2018-03-23 19:01:39", updated_at: "2018-03-23 19:01:39">
Rails.application.routes.url_helpers.polymorphic_url(u, :only_path => true)
#=> "/users/1"
Rails.application.routes.url_helpers.polymorphic_url(u, :host => "example.com")
#=> "http://example.com/users/1" I'm not sure if this one-liner is worth extraction into a separate gem. Even though it's bit hackish. cc @PeterTKY |
There are actually some use cases can't be handled easily by polymorphic_url. Example: We have three model classes, Restaurant::Chinese, Restaurant::Japanese and Restaurant::Western. In config/routes.rb:
In console:
We have to call:
But then the :restaurants_chinese is not intuitive to have. We can't simply use the model instance in polymorphic_url like other cases. |
The object_path/object_url method should generate correct path/url as the routes defined in a Rails application. It should handle properly even if the routes are actually defined in a Rails engine and mounted in the application.
The text was updated successfully, but these errors were encountered: