I am trying to configure omniauth-facebook to fetch user friends.
This is my configuration:
ActionController::Dispatcher.middleware.use OmniAuth::Builder do
provider :facebook, "xxxxxx", "xxxxxxxx",
:info_fields => 'friends'
end
I am using Rails 2.3.
I am using this code in view:
<div id="contacts">
</div>
<script type="text/javascript" charset="utf-8">
$('contacts').innerHTML = '<%= request.env['omniauth.auth'].keys %>';
</script>
I am not sure why the script is not being executed, but when I copy:
$('contacts').innerHTML = 'infouidcredentialsextraprovider';
in console after page has loaded it works replacing content of div with that text.
There is no error message in browser console.
Why script does not get executed? I tried with console.log too, and I had no luck.
The info_fields option is still new and so you will have to wait for a new release of the omniauth-facebook gem.
In the meantime, you can try using the master branch by changing your Gemfile to:
gem 'omniauth-facebook', :github => 'mkdynamic/omniauth-facebook'
As for debugging, you can get the information returned from facebook by adding the following as the first line of your callback controller:
raise request.env["omniauth.auth"].to_yaml
Now try to login and you'll be able to take a good look at the hash of nested hashes returned.
Related
I tried several gems for use Server Side GA.
=> Stacato
=> Gabba
=> ...
But I have always the same problem, in google analytics the SOURCE of all my events are in "Direct" (direct traffic), even if i use utm_source, ...
I remarked, each time I trigger an event, Google analytics create a new session with source "Direct" (and a location in United states), and I think the event is attributed to this session and no to my effective session.
My config (with the gem Gem Gabba https://github.com/hybridgroup/gabba ):
View application.html.erb
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXXXXX-1', 'auto');
ga('send', 'pageview');
</script>
Model User
Gabba::Gabba.new("UA-XXXXXX-1", "mysite.com").event('User', 'Signup', 'Profile completed')
I have a doubt if it's a configuration problem or if it's a recurrent problem when you use a Server Side GA?
Thx #eike & #RaV, you help me to find a solution.
I removed the gabba gem and added staccato gem instead.
The problem was the same (staccato generated a new client_id by default, that's why I had a duplicate), but I figured out how to fix it.
1.Just save the client_id from in the google analytics cookie in your application controller:
before_action :tacking_ga
def client_id
cookies["_ga"].split(".").last(2).join(".")
end
private
def tacking_ga
#tracker = Staccato.tracker('UA-XXXXXXXXX-1', client_id, ssl: true) if Rails.env == "production"
end
2.After that in my controller (example user_controller) I just had to add my event at the right place:
#tracker.event(category: 'User', action: 'Signup', label: "Profile completed", value: nil)
Thx for your help
I'm following along with the Angular/Rails tutorial at Thinkster and I've run into an issue which seems to be most likely be Angular-related. Everything works just fine until I get to the Angular Routing section. Simply put, the inline templates within the <script> tags do not load in the <ui-view></ui-view> element. I originally thought this may be due to having opened the page locally as a file rather than having it loaded from a server, but the same problem persists even after integrating Rails (using an older version of Sprockets, as pointed out in this similar but unrelated issue).
When I load the index page in either the browser as a file or as a URL when running the Rails server, I've inspected the HTML and, sure enough, the only thing it shows in the code are the divs and an empty <ui-view> element, indicating something just isn't adding up correctly. I've tried various things, including:
Using the newest version of ui-router (0.2.15 at this writing) rather than the version in the tutorial
Using <div ui-view></div> instead of <ui-view></ui-view>
Changing the value of 'url' in the home state to 'index.html', including using the full path to the file (file:///...)
Putting the contents of the inline <script> templates into their own files (without the <script> tags, of course) and specifying the 'templateUrl' field using both relative and full paths
Trying both Chrome and Firefox just to be extra certain
None of these things have worked, even when accessing http://localhost:3000/#/home when the Rails server is running after having integrated Angular into the asset pipeline in the Integrating the Front-end with the Asset Pipeline section of the tutorial. Indeed, the route loads but does not show anything more than a completely blank page with a lonesome and empty <ui-view> element when inspecting the HTML using Chrome's dev tools.
Given that the issue seems to occur even before the Rails portion, it does seem like something to do with Angular itself, but I've got no clue what's going on, especially since I've followed along to the letter.
I'm using Bower to manage the Angular dependencies and the HTML does show that the Angular javascript files in both the app/assets/javascripts directory and in the vendor/assets/bower_components directory are being loaded properly in the <head> section, so everything seems to be okay on the asset pipeline integration.
Versios I'm using:
Rails: 4.2.3
Ruby: 2.2.1p85
Angular: 1.4.3
ui-router: 0.2.15
The code I've got for the major moving parts is below:
app/views/layouts/application.html.erb
<!DOCTYPE html>
<html>
<head>
<title>Test App</title>
<%= stylesheet_link_tag 'application', media: 'all' %>
<%= javascript_include_tag 'application' %>
<%= csrf_meta_tags %>
</head>
<body ng-app="testApp">
<div class="row">
<div class="col-md-6 col-md-offset-3">
<ui-view></ui-view>
</div>
</div>
</body>
</html>
app/assets/javascripts/app.js
angular.module('testApp', ['ui.router', 'templates']).config(['$stateProvider', '$urlRouteProvider', function($stateProvider, $urlRouteProvider) {
$stateProvider
.state('home', {
'url': '/home',
'templateUrl': 'home/_home.html',
'controller': 'MainCtrl'
})
.state('posts', {
'url': '/posts/{id}',
'templateUrl': 'posts/_posts.html',
'controller': 'PostsCtrl'
});
$urlRouteProvider.otherwise('home');
}]);
app/assets/javascripts/application.js
//= require angular
//= require angular-rails-templates
//= require angular-ui-router
//= require_tree .
app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
respond_to :json
def angular
render 'layouts/application'
end
end
config/routes.rb
Rails.application.routes.draw do
root to: 'application#angular'
end
app/assets/javascripts/home/mainCtrl.js
angular.module('testApp').controller('MainCtrl', ['$scope', 'posts', function($scope, posts) {
$scope.posts = posts.posts;
$scope.addPost = function() {
if (!$scope.title || $scope.title === "")
return;
$scope.posts.push({
'title': $scope.title,
'link': $scope.link,
'upvotes': 0,
'comments': [
{'author': 'Some Person', 'body': 'This is a comment.', 'upvotes': 0},
{'author': 'Another Person', 'body': 'This is also a comment.', 'upvotes': 0}
]
});
$scope.title = "";
$scope.link = "";
};
$scope.incrementUpvotes = function(post) {
post.upvotes++;
};
}]);
app/assets/javascripts/posts/postsCtrl.js
angular.module('testApp').controller('PostsCtrl', ['$scope', '$stateParams', 'posts', function($scope, $stateParams, posts) {
$scope.post = posts.posts[$stateParams.id];
$scope.addComment = function() {
if($scope.body === '')
return;
$scope.post.comments.push({
'body': $scope.body,
'author': 'user',
'upvotes': 0
});
$scope.body = '';
};
}]);
app/assets/javascripts/posts/posts.js
angular.module('testApp').factory('posts', ['$http', function($http) {
var o = {
'posts': []
};
o.getAll = function() {
return $http.get('/posts.json').success(function(data) {
angular.copy(data, o.posts);
});
};
return o;
}]);
If any other code is required to help uncover the problem, please let me know and I'll supply anything requested.
it seems that the angular-ui-router is incompatible with the new Rails sprockets. To fix this, add this earlier version of sprockets to your gemfile:
gem 'sprockets', '2.12.3'
And then run bundle update sprockets.
This was answered a few times in other similar questions, like the one below:
Angular Rails Templates just not working
$urlRouteProvider in my code should've been $urlRouterProvider. Be sure to double-check everything, folks, and make good use of the console!
I'm a rails noob so I know I'm probably totally missing something here. I'm trying to pass a url to an iframe through my products controller.
This is my setup.
Products Controller
def open_url
#url = params[:url]
end
index.html.erb
<%= link_to "More Info", open_path(url: "http://www.ceratoboutique.com" + product.destination_url) %>
open_url.html.erb
<iframe src= "<%= #url %>" style="border: 0; position:fixed; top:0; left:0; right:0; bottom:0; width:100%; height:100%" />
routes.rb
get '/open' => 'products#open_url', via: 'get'
I,ve checked out these two questions
Rails 4 - Passing Params via link_to?
Opening a Link in a New Window within an iFrame
but i'm still lost, the url is passed to the browser but it does not seem to pass to the #url variable in my controller.
Debug Dump
!ruby/hash:ActionController::Parameters
url: http://www.ceratoboutique.com/collections/tops/products/combo-blouse
controller: products
action: open_url
I decided to stick to rails conventions and make it a restful link. I still do not know why the original implementations did not work, but it worked using the show method in the controller.
Controller
def show
#url = Product.find(params[:id])
end
index.html.erb
<%= link_to "More Info", product_path(product) %>
show.html.erb
<iframe src= "<%= "http://www.ceratoboutique.com" + #product.destination_url %>" style="border: 0; position:fixed; top:0; left:0; right:0; bottom:0; width:100%; height:100%" />
****Edit Added More Info for including I-Frame ****
I ran into a lot of problems trying to get my iframe to work in chrome and on Heroku so I combined the process if anyone needs it ever. I first deployed to Heroku with full SSL running on my site, then realized that iframe did not work in chrome for sites that were not running SSL. I redeployed configuring force SSL to false, but heroku still forced my app to SSL. I realized that config.force_ssl = true enables Strict Transport Security header(HSTS) with max-age of one year, so I had to expire HSTS using the following.
Expire SSL in application controller
class ApplicationController < ActionController::Base
before_filter :expire_hsts
def expire_hsts
response.headers["Strict-Transport-Security"] = 'max-age=0'
end
In Production.rb
config.force_ssl = false
Then to make sure the x-frame showed in chrome browsers I added the following.
enable x-frame in chrome
config.action_dispatch.default_headers = { 'X-Frame-Options' => 'ALLOWALL' }
You may want to run SSL on some of your pages, which can be done rather easily via the SSL enforcer gem linked below.
ssl-enforcer gem
https://github.com/tobmatth/rack-ssl-enforcer
Best of luck on navigating the ugliness that is the iFrame!
I am trying to integrate a Rails App with ActiveCampaign CRM using the following gem: https://github.com/RushPlay/active_campaign
ac = ActiveCampaign::Client.new({:api_method => 'https://website.api-us1.com',:api_key => 'mykey'})
response = ac.contact_sync({ :email => "test#test.com",:first_name => "John",:last_name => "Doe" })
The request is unsuccessful and Rails returns this:
undefined method `query=' for #<HTTPI::Request:0x007f914b61f8d0>
Any idea why this might be? I've been trying to figure it out for a while, and can't get to the bottom of it...
UPDATE
I tried updating my HTTPI gem to a newer version (2+) and the original error disappeared, but now I am seeing the following error:
757: unexpected token at '<div align="center">
<div style="font-size:15px; color:#333; padding: 50px; font-family:Arial, Helvetica, sans-serif;">
<div style="font-size:33px; padding:12px;">Not Found</div>
<div>Sorry, this page could not be found.<br />
Please check your link/URL and try again.</div>
</div>
</div>'
Any ideas?
active_campaign's gemspec doesn't specify a httpi version, looking at the commit that added the query= method, it looks like it's been in there since 2.0.
Do you have an old (1.x) version of httpi in your Gemfile.lock? If you bundle up httpi, does it help?
I cannot get the galetahub ckeditor gem to work with Rails 4 for me. I searched for any problems online but cannot find any. I'm following the instructions exactly.
I include gem "ckeditor" in my Gemfile
I include gem "carrierwave" and gem "mini_magick"
I run rails generate ckeditor:install --orm=active_record --backend=carrierwave
I run rake db:migrate
Inside application.rb I include config.autoload_paths += %W(#{config.root}/app/models/ckeditor)
Inside routes.rb I have mount Ckeditor::Engine => '/ckeditor'
I'm using SimpleForm so I paste the following ERB <%= f.input :description, as: :ckeditor %> in my view.
And I think that's it. But my text area does not convert to a CKeditor area for some reason.
STEP 1: Add gem 'paperclip' and gem "ckeditor" in your gemfile.
STEP 2: Bundle Install.
STEP 3: rails generate ckeditor:install --orm=active_record --backend=paperclip
STEP 4: Place config.autoload_paths += %W(#{config.root}/app/models/ckeditor) in application.rb
STEP 5: Place mount Ckeditor::Engine => "/ckeditor" if not present in routes.rb already and run db:migrate
STEP 6: Open application.html.erb and place this <%= javascript_include_tag 'ckeditor/ckeditor.js' %> in header.
STEP 7: Place this in footer(above the body tag) in application.html.erb
<script type="text/javascript">$(document).ready(function() {
if ($('textarea').length > 0) {
var data = $('textarea');
$.each(data, function(i) {
CKEDITOR.replace(data[i].id);
});
}
});</script>
STEP 8: Restart the WEBrick SERVER.
That's it.
Else
Download the CKEditor Zip file, extract the files and place them in the sub directory “javascripts/ckeditor”, add the main JS file to the layout..
javascript_include_tag 'ckeditor/ckeditor.js'
Place this in footer(above the body tag) in application.html.erb
<script type="text/javascript">$(document).ready(function() {
if ($('textarea').length > 0) {
var data = $('textarea');
$.each(data, function(i) {
CKEDITOR.replace(data[i].id);
});
}
});</script>
I have the same problem using rails 4 and apparently the problem is that the form helper
form.cktext_area
Or in your case
f.input :description, as: :ckeditor
it's not generating what it supposed to generate, and you don't have to load the editor manually, the only thing you need to do is to is to add the class 'ckeditor' to your textarea and it will load automatically, like this:
f.cktext_area :body, :class => 'ckeditor'
Meanwhile the Galetahub gem has been updated, but it has to be updated in your app manually. Read the github page: https://github.com/galetahub/ckeditor.
ajkumar basically answered the question well already, but if you are still lost, all you need to do is download the js file, include it in your html, have a script snippet included in the HTML to activate ckeditor on a certain textarea tag ID, and then change the class of the "textarea" tag you want to change to ckeditor. Quick sample below
<!DOCTYPE html>
<html>
<head>
<title>A Simple Page with CKEditor</title>
<!-- Make sure the path to CKEditor is correct. -->
<script src="../ckeditor.js"></script>
</head>
<body>
<form>
<textarea name="editor1" id="editor1" rows="10" cols="80">
This is my textarea to be replaced with CKEditor.
</textarea>
<script>
// Replace the <textarea id="editor1"> with a CKEditor
// instance, using default configuration.
CKEDITOR.replace( 'editor1' );
</script>
</form>
</body>
</html>
The galetahub gem is currently broken on Rails 4. This one is working fine though: https://github.com/tsechingho/ckeditor-rails
In case you are having trouble making it work with active admin, make sure to put this:
config.register_javascript 'ckeditor/ckeditor.js'
config.register_javascript 'ckeditor/init.js'
Into config/initializers/active_admin.rb