devise/omniauth issue using pow - working on rails server - ruby-on-rails

I'm using pow to host my rails app locally.
I've added devise and am trying to get omniauth to work following these steps.
when I visit http://my_site.dev/users/auth/twitter I get the following error -
URI::InvalidURIError
the scheme http does not accept registry part: my_site.dev (or bad hostname?)
Using the internal rails server works fine, visiting http://0.0.0.0:3000/users/auth/twitter works as expected.
Any idea what I'm doing wrong? Do I need to change something within pow?

Hostnames are not allowed to include underscores. Try this:
$ mv ~/.pow/my_site ~/.pow/my-site
The site will now be available under http://my-site.dev/.

You will need to edit your etc/hosts and set host there next go to twitter configuration page and set this url there. Probably it is set to localhost or something like this so he is not eager to trust it :).

Related

Rails params nulled when responding to csv format in production

I'm having a weird problem I cannot seem to figure out related to rails params.
I have a Controller where I permit any param. In this controller, a param (csv_type) controls which CSV file I will respond. CSV of type registration or attendance, for example.
This param is built in URL via path (e.g.: abcs_path(#abc, format: 'csv', csv_type: 'attendance') resulting in /abcs/id.csv?csv_type=attendance.
I would expect {"csv_type"=>"attendance", "controller"=>"abcs", "action"=>"show", "id"=>"45", "format"=>"csv"} but in production I get {"controller"=>"abcs", "action"=>"show", "id"=>"45", "format"=>"csv"}. csv_type is gone.
This works flawlessly locally and I get all params. Also works well on Heroku review apps. Also works well when I run locally on RAILS_ENV=production.
But in real production, it doesn't. It also doesn't work on staging which is configured with RAILS_ENV=production. Though review apps are also RAILS_ENV=production, which makes the whole thing a mystery.
Ideas:
- nginx messing up with domain (staging and production are on official domain, review app is Heroku domain, local is localhost).
- sqreen somehow intercepting this
- mime.types and https (have tried adding csv to rails, with no success). Didn't add on nginx
- some rails config on params permit (though I'm doing params.permit!) on before_action just to make sure
- some ENV variable messing up?
- can't think of anything else ???
Thanks in advance for the help!

405 not allowed nginx, CORS? Nginx config? Or something else?

Working on an app built using Ember.js and Rails.
Authentication is being done with ember-simple-auth using Oauth2.
I am able to login to my app locally in my development environment, but as soon as I try to login on my production server (through Heroku) I start receiving a nginx 405 not allowed status code.
First thing I thought was maybe it is my request headers / CORS. I am using rack-cors gem on my rails side and configured it based directly off the readme example. Here is my application.rb
Researching, I found the same problem with the solution being to configure Nginx side of things, but I figured since that is being handled by heroku I wasn't really sure if that was where I need to make my changes.
Let me know if there are any other files/info that could help.
What is the best way to debug this problem?
Try using this first to rule out CORS:
https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi
Does the route work locally when you use Postman or a similar tool?
Are you requesting HTML or JSON?

Do I need to change nginx configuration to set up a subdomain for my Rails app?

I am having a problem testing a subdomain for my app. I read in a post that lvh.me will translate into localhost. This has worked well for me in my development environment. I've modified my rails app's routes.rb to have this code:
constraints(Codeopenhub) do
get '/', to: 'codeopenhub#index'
get '/*other', to: 'codeopenhub#index'
end
Basically the code is saying that if you hit code.openhub.net/anything, you'll hit a particular page. Now when I deploy this onto my staging environment, this doesn't work at all. Hitting the subdomain says that the site can't be reached. server DNS address could not be found. Do I need to add an accompanying modification to nginx/sites-enabled or nginx/sites-available? Or perhaps I need an entry in /etc/hosts?
I was following these resources but now I'm a bit stuck and hit a wall. Could someone lend me a hand? It would be greatly appreciated.
Dealing with Subdomains
Capybara and Subdomains

Redirection in RubyOnRails

I just got an SSL certificate for "example.com". After making some configurations in NGINX I could finally redirect "http://www.example.com" calls and "http://example.com" calls to "https://example.com". Everything works fine, but when I type "https://www.example.com" an SSL error is shown. Is there a way to redirect "https://www.example.com" calls to "https://example.com" using some Ruby code?
Handling the redirect at the Rack level and not inside of the Rails app is my preferred way to solve this requirement.
https://github.com/jtrupiano/rack-rewrite#scheme
The link takes you to the part of the README that addresses this question. I've used this gem in the past and it works really well.

How to get subdomain fu working in development on my local machine

I cloned a github repo using subdomain fu but I can't seem to get the site to load properly. I always get the same error:
I tried signin.localhost.local:3000, which seems to be working to get the signin/signup pages working. However, when I go to login (from signin.localhost.local:3000) it keeps "signin" at the front like so:
sub1.signin.localhost.local:3000
in prod it works perfectly but for some reason it keeps signin here when it is not suppose to. Also, if I try just removing "signin" and going to sub1.localhost.local:3000, it tells me again "can't find account with subdomain = ". very frustrating.
Here is my hosts file right now:
127.0.0.1 localhost signin.localhost.local sub1.localhost.local signup.localhost.local
Working with subdomains in development mode can be really tricky. If you're on a Mac and the project is using a reasonably recent version of Rails, I'd recommend using Pow which will let you use subdomains without any fancy trickery.
Once you've installed it, you can add a symlink to a project to your ~/.pow directory and then access the app at app_name.dev and use subdomains, such as signin.app_name.dev as well.
Just to confirm, you are restarting apache?

Resources