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

Default Version for A Specific Route #45

Open
LBRapid opened this issue Mar 3, 2016 · 3 comments
Open

Default Version for A Specific Route #45

LBRapid opened this issue Mar 3, 2016 · 3 comments

Comments

@LBRapid
Copy link

LBRapid commented Mar 3, 2016

Is there a way to set the default version just for one route/controller action?

I want to use the latest version available for all api resources except one. For this resource, I would like it to use version 1 of the api unless a specific api version is specified.

Let me know if you need more information to understand my question. Overriding the default_version config works for the time being, but I would like to implement this in a way that going forward it might work for multiple resources.

@bwillis
Copy link
Owner

bwillis commented Mar 3, 2016

Interesting use case! I don't see an easy way to support this now, but can think of a couple ways to go about this:

before_actions

class PostsController < ApplicationController
  prepend_before_action :override_latest_version, only: :show, if: :'request_version_missing?' # this API doesn't exist yet

  def index;end

  def show;end

  private

  def override_latest_version
    set_version 1
  end
end

configuration

VersionCake.setup do |config|
  config.resources do |r|
    r.resource %r{.*}, [], [], (1..4), 1 # overrides the global missing_version
  end
  config.extraction_strategy = :query_parameter # for simplicity
  config.missing_version = 4
end

What do you think?

@LBRapid
Copy link
Author

LBRapid commented Mar 3, 2016

Both methods look pretty good.

I think I prefer the second method to the prepend_before_filter option. It would allow for all Versioncake configuration to stay together, rather than having to add extra things to a controller.

@bwillis
Copy link
Owner

bwillis commented Mar 4, 2016

Yeah, agree with keeping the config together and it allows for non-Rails apps to use the functionality easier.

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

No branches or pull requests

2 participants