-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Add Rails url_helpers #1550
Add Rails url_helpers #1550
Conversation
The tests need some fixing but I'd like to start getting eyes on this. |
💯 |
link :link_name, 'https://example.com/resource' | ||
``` | ||
|
||
As a block to be evaluated. When using Rails, URL helpers are available. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Should also add a
/howto/
for configuring theSupport::UrlHelpers
(after the meat of the PR is reviewed)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- would be good to have
url_for
example and maybedefault_url_options
?
which might go in the configuration
docs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since having revised this PR to use SerializationContext
I think we need:
- Docs for configuring
Rails.application.routes.default_url_options
- Docs that give an example of
url_for
. (as previously mentioned)
Anything else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests w grape adapter?
B mobile phone
On Mar 3, 2016, at 12:14 PM, Ben Mills [email protected] wrote:
Since having revised this PR to use SerializationContext I think we need:
Docs for configuring Rails.application.routes.default_url_options
Docs that give an example of url_for. (as previously mentioned)
Anything else?—
Reply to this email directly or view it on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I figured when Grape is used with Rails, the Railtie would load and SerializationContext would be available and include the url helpers. When Grape is used without Rails, the railtie would not load, SerializationContext would not be available, and no url helpers would be available. Are you wanting more of an explicit test? It doesn't look like links are even tested under Grape.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have a grape impl, but let's not delay this pr
B mobile phone
On Mar 3, 2016, at 2:41 PM, Ben Mills [email protected] wrote:
In docs/general/rendering.md:
@@ -144,6 +144,32 @@ That's the result:
This feature is specific to JsonApi, so you have to use the use the JsonApi Adapter
+##### Resource-level
+
+In your serializer, define each link in one of the following methods:
+
+As a static string
+
+ruby +link :link_name, 'https://example.com/resource' +
+
+As a block to be evaluated. When using Rails, URL helpers are available.
I figured when Grape is used with Rails, the Railtie would load and SerializationContext would be available and include the url helpers. When Grape is used without Rails, the railtie would not load, SerializationContext would not be available, and no url helpers would be available. Are you wanting more of an explicit test? It doesn't look like links are even tested under Grape.—
Reply to this email directly or view it on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, sorry for a little yagni i introduced
B mobile phone
On Mar 3, 2016, at 2:41 PM, Ben Mills [email protected] wrote:
In docs/general/rendering.md:
@@ -144,6 +144,32 @@ That's the result:
This feature is specific to JsonApi, so you have to use the use the JsonApi Adapter
+##### Resource-level
+
+In your serializer, define each link in one of the following methods:
+
+As a static string
+
+ruby +link :link_name, 'https://example.com/resource' +
+
+As a block to be evaluated. When using Rails, URL helpers are available.
I figured when Grape is used with Rails, the Railtie would load and SerializationContext would be available and include the url helpers. When Grape is used without Rails, the railtie would not load, SerializationContext would not be available, and no url helpers would be available. Are you wanting more of an explicit test? It doesn't look like links are even tested under Grape.—
Reply to this email directly or view it on GitHub.
I agree with @bf4 that SerializationContext approach would be better than including ActionMailer |
I strongly prefer the SerializationContext method of handling this. Revising this PR. |
|
||
If you wish to use Rails url helpers for link generation, e.g., `link(:resources) { resources_url }`, ensure your application sets | ||
`Rails.application.routes.default_url_options`. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dup text maybe instead link one to other?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know. I was thinking it would be easy to miss this in several places if it just linked to once section.
@@ -144,6 +147,33 @@ That's the result: | |||
|
|||
This feature is specific to JsonApi, so you have to use the use the [JsonApi Adapter](adapters.md#jsonapi) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
jsonapi only true for resource-level, also, right?
Might it be helpful to just refer to json_api/links.md
or how_to/links.md
for most of the text here to keep the rendering.md slimmer and more general?
ok for followup pr
💯 ok to merge |
@remear I'm wondering how the these default URL options can be set/mutated specifically in the case of So far I've tried setting:
|
@mecampbellsoup I configure this from Rails.application.routes.default_url_options = {
host: ENV['EXTERNAL_HOST'] || 'localhost:3000',
protocol: ENV['EXTERNAL_HOST_PROTOCOL'] || 'http'
} |
Purpose
Add Rails url_helpers to Link so helpers are available in the evaluation context for the block. This allows
link(:link_name) { resource_url(object) }
Changes
url_helpers
anddefault_url_options
inSerializationContext
via the railtie.Caveats
Related GitHub issues
#1454