Skip to content

Commit

Permalink
Merge pull request #350 from aarongray/master
Browse files Browse the repository at this point in the history
Fix concern not being inserted for rails-api apps.
  • Loading branch information
booleanbetrayal committed Aug 21, 2015
2 parents 721d8bb + 0db531e commit 7ee4ec3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
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

0 comments on commit 7ee4ec3

Please sign in to comment.