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

Fix concern not being inserted for rails-api apps. #350

Merged
merged 1 commit into from
Aug 21, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ The following events will take place when using the install generator:

* Routes will be appended to file at `config/routes.rb`. [Read more](#mounting-routes).

* A concern will be included by your application controller at `app/controllers/application_controller.rb`. *If you are using `rails-api` instead of vanilla rails, you will need to add this concern manually.* [Read more](#controller-methods).
* A concern will be included by your application controller at `app/controllers/application_controller.rb`. [Read more](#controller-methods).

* A migration file will be created in the `db/migrate` directory. Inspect the migrations file, add additional columns if necessary, and then run the migration:

Expand Down
11 changes: 11 additions & 0 deletions lib/generators/devise_token_auth/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ def include_controller_concerns
if File.exist?(File.join(destination_root, fname))
if parse_file_for_line(fname, line)
say_status("skipped", "Concern is already included in the application controller.")
elsif is_rails_api?
inject_into_file fname, after: "class ApplicationController < ActionController::API\n" do <<-'RUBY'
include DeviseTokenAuth::Concerns::SetUserByToken
RUBY
end
else
inject_into_file fname, after: "class ApplicationController < ActionController::Base\n" do <<-'RUBY'
include DeviseTokenAuth::Concerns::SetUserByToken
Expand Down Expand Up @@ -116,6 +121,12 @@ def parse_file_for_line(filename, str)
match
end

def is_rails_api?
fname = "app/controllers/application_controller.rb"
line = "class ApplicationController < ActionController::API"
parse_file_for_line(fname, line)
end

def json_supported_database?
(postgres? && postgres_correct_version?) || (mysql? && mysql_correct_version?)
end
Expand Down