Skip to content

Commit f5e6fad

Browse files
committed
Merge pull request #23 from intercom/install_improvements
Config generation improvements
2 parents 9798669 + 0c3ce5c commit f5e6fad

File tree

4 files changed

+27
-40
lines changed

4 files changed

+27
-40
lines changed

README.mdown

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,6 @@ You can also override `IntercomRails::Config` options such as your `api_secret`,
151151
}) %>
152152
<% end %>
153153
```
154-
155-
The `intercom:install` rails generator will add the `intercom_script_tag` to your application layout:
156-
157-
```
158-
rails g intercom:install YOUR-APP-ID
159-
```
160-
161154
## Importing your users
162155
To get started faster with Intercom, `IntercomRails` includes a Rake task that will do an initial import of your users:
163156

lib/rails/generators/intercom/config/config_generator.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,34 @@ def self.source_root
1010
argument :api_secret, :desc => "Your Intercom api-secret, used for secure mode", :optional => true
1111
argument :api_key, :desc => "An Intercom API key, for various rake tasks", :optional => true
1212

13+
FALSEY_RESPONSES = ['n', 'no']
1314
def create_config_file
1415
@app_id = app_id
1516
@api_secret = api_secret
1617
@api_key = api_key
1718

19+
introduction = <<-desc
20+
Intercom will automatically insert its javascript before the closing '</body>'
21+
tag on every page where it can find a logged-in user. Intercom by default
22+
looks for logged-in users, in the controller, via 'current_user' and '@user'.
23+
24+
Is the logged-in user accessible via either 'current_user' or '@user'? [Yn]
25+
desc
26+
27+
print "#{introduction.strip} "
28+
default_ok = $stdin.gets.strip.downcase
29+
30+
if FALSEY_RESPONSES.include?(default_ok)
31+
custom_current_user_question = <<-desc
32+
33+
How do you access the logged-in user in your controllers? This can be
34+
any Ruby code, e.g. 'current_customer', '@admin', etc.:
35+
desc
36+
37+
print "#{custom_current_user_question.rstrip} "
38+
@current_user = $stdin.gets.strip
39+
end
40+
1841
template("intercom.rb.erb", "config/initializers/intercom.rb")
1942
end
2043

lib/rails/generators/intercom/config/intercom.rb.erb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ IntercomRails.config do |config|
2727
# The method/variable that contains the logged in user in your controllers.
2828
# If it is `current_user` or `@user`, then you can ignore this
2929
#
30+
<%- if @current_user -%>
31+
config.user.current = Proc.new { <%= @current_user %> }
32+
<%- else -%>
3033
# config.user.current = Proc.new { current_user }
34+
<%- end -%>
3135

3236
# == User model class
3337
# The class which defines your user model

lib/rails/generators/intercom/install/install_generator.rb

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)