Skip to content
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

URLs include version parameter #91

Open
manuelmeurer opened this issue Feb 18, 2014 · 7 comments
Open

URLs include version parameter #91

manuelmeurer opened this issue Feb 18, 2014 · 7 comments

Comments

@manuelmeurer
Copy link
Contributor

I'm using RocketPants with Rabl. When I render a URL in a Rabl template, the version parameter is always added by default:

# config/routes.rb
MyApp::Application.routes.draw do
  get 'foo' => 'foo#bar' # Only for testing
  namespace :api, path: '', constraints: { subdomain: 'api' } do
    api version: 1, require_prefix: 'v', module: 'v1' do
      resources :widgets
    end
  end
end

# app/views/api/v1/widgets/index.json.rabl
collection @widgets
node :foo do |widget|
  foo_path
end

# returned JSON:
{
  results: [
    {
      foo: "/foo?version=v1"
    }
  ]
}

When I add version: nil to the URL helper call, it disappears:

foo_path version: nil

Is this intended behavior?

@Sutto
Copy link
Owner

Sutto commented Feb 25, 2014

For the moment, yes - the idea being you're typically generating links internal to the API.

It might make sense to make it be smarter about generating them only for api routes (which it doesn't at the moment) but that would take a bit more work.

@manuelmeurer
Copy link
Contributor Author

@Sutto
Copy link
Owner

Sutto commented Mar 2, 2014

It's used so that when we generate links in the api to other API endpoints, it automatically includes the version the current user has specified, so they're consistent in linking.

@manuelmeurer
Copy link
Contributor Author

Ah ok, makes sense. But is this the moment where the version parameter is added to non-API URLs as well? Could we not check there if the URLs is for the API, and only add the parameter if it is?

@toobulkeh
Copy link

@manuelmeurer I know this is an old task, but how did you get RP to render RABL files? I found another post, but it's not very elegant. Thanks!

@manuelmeurer
Copy link
Contributor Author

@toobulkeh This is pretty much all it needs: https://gist.github.com/manuelmeurer/27cb13fb7bdbba49706a

@toobulkeh
Copy link

very similar. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants