Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
kayakyakr
Feb 16, 2004

Kayak is true
e: ^^^ github pages are also good for static apps. It's http://nestacms.com/ on the back end if i'm not mistaken.

DreadCthulhu posted:

Rails migrations are by default wrapped into a transaction, correct?

for databases that support transactions, yes.

Adbot
ADBOT LOVES YOU

kayakyakr
Feb 16, 2004

Kayak is true

KoRMaK posted:

Is this in regards to my question? My app isn't going to be static.

then to heroku you go!

kayakyakr
Feb 16, 2004

Kayak is true

Sil posted:

Rspec is loving with me tonight. I think.

I have a setup with sucker_punch(a celluloid thingy) that sends emails asynchronously for me. It works perfectly in production and development.

When I go to test it with Rspec and Capybara suddenly database records start vanishing the moment my application switches into the sucker_punch class(aka the celluloid actor). I try to use sucker_punch's inline testing whatever options, does nothing. It doesn't wipe all records, I don't have Database Cleaner running. I am at a complete loss.

Are you trying to send emails from an after_save? If so, you're probably hitting a race condition and should switch to after_commit.

kayakyakr
Feb 16, 2004

Kayak is true

Sil posted:

Holy moly, you're my god!

That being said I still think it's weird. I checked the database during the before_save and the record is there, then I check the database in the after_save and the record isn't there anymore. This likely reflects my misunderstanding of how ActiveRecord works, but still. Also it was never a problem in development/production. You know, when actually sending the email over smtp. Presumably the lag of authorizing with gmail allowed AR to catch up with itself? Or something?

Granted I don't quite understand how Celluloid/sucker_punch works either. Time to make some additions to the READTHIS bookmarks folder.

If you're seeing the record in the database in a before_save, then you're doing something wrong as before save literally means before it's been saved. The after save should show the database record, though.

I'll explain to you why it wasn't working in test mode but was in production/development, though. Every save/update/delete/etc in rails is wrapped in a transaction (or psuedo-transaction). When you're inside the scope of that transaction, everything works fine, but outside that scope, nothing that you've done inside can be seen.

In production/development, sucker_punch (or in other words, celluloid) gets that async call, spins up a new thread, and then does what it's going to do. This creates a race condition, but it's taking long enough that the save wins the race most of the time. I'm guessing that if you load the system down, the save will start to lose the race and you'll get a bunch of failed emails.

In test mode, sucker_punch runs everything single-threaded, no async, but still manages to access active record outside of the scope of the transaction. So you spin up the email service before committing the transaction, the email service is looking from the outside-in and can't see what's gone on inside the transaction.


And I've never liked the idea of wrapper classes. It's a neat idea, but you start abstracting behaviors away from the classes that they're managing and now have two places where people can screw things up. Though using a wrapper class to manage saves is, in my opinion, a better pattern than observers which always seemed so loose to me.

kayakyakr
Feb 16, 2004

Kayak is true

wolffenstein posted:

I'm trying to make this snippet for extending the Mechanize gem work with my Rails 4 project, but the only advice I got from #rubyonrails was put in in the /lib directory. Numerous searches show how to add /lib to autoload, but they don't seem to work with the snippet. Any ideas?

You shouldn't make a habit of it, but a lot of people throw monkey patches into initializers. I would suggest requiring the file manually, instead. i'm not a fan of adding your entire lib to autoload unless you really need to.

kayakyakr
Feb 16, 2004

Kayak is true

KoRMaK posted:

I'm starting my first app from scratch. I have about 2 years in on another project that I inherited after it was setup with a custom config. There isn't really a problem, but I notice a difference when I scaffold. With my new app the models have all their variables mentioned via attr_accessible. The other app doesn't do this. The only time it does is for when something gets added to the account model. My guess is that the account model was made before the gem or config option that controls this. Can anyone suggest what gem/option controls this?

What version of rails is your old project? And your new? There have been significant changes in rails over the years, first adding attr_accessible and then switching to the aforementioned strong parameters. If you're generating a new app, I would highly suggest choosing rails 4 now so you don't have to deal with upgrade heartburn later.

kayakyakr
Feb 16, 2004

Kayak is true

KoRMaK posted:

Ruby 1.9.2, Rails 3.2.13. They both have that in common. Strong Parameters doesn't look familiar. The older project inherits a proprietary setup called Rails Saas kit so maybe its from that.

Rails 3.2 should be generating attr_accessible with scaffolds. what happens if you generate a model?

Still highly recommend switching to rails 4. Strong parameters is the only thing that I really noticed.

kayakyakr
Feb 16, 2004

Kayak is true

KoRMaK posted:

But why does one do it and not the other.

Can't tell ya. Are you sure that you generated the scaffold with attributes? It's part of the rails 3.2 generator natively, so if you aren't seeing it... run:

code:
rails -v
and make sure you are actually using rails 3.2 like you think you are.

kayakyakr
Feb 16, 2004

Kayak is true
Could make the unregistered users into actual users, give them a random password, save an "unregistered" state on the user model, and prompt them to fully register if you need?

kayakyakr
Feb 16, 2004

Kayak is true

Fillerbunny posted:

I'm starting work on a project, and am considering building it on Heroku for visibility purposes and porting it to the customer's server once it's accepted/completed. Is this an okay idea? Is there anything I should know up front?

If you're able to run it on the heroku freebie server for development, then you should be fine. If you need more server or background tasks or more database than you can get for free, I'd suggest capistrano + either the AWS free tier EC2 server or a $5 digital ocean server. That'd make it easier to deploy to the customer's server as well, since it'd be set up for that sort of architecture in the first place.

kayakyakr
Feb 16, 2004

Kayak is true

Molten Llama posted:

DigitalOcean's pretty great for isolated VMs. Two things to be aware of if you need to split services across multiple VMs:

1. Only NYC2 instances have any form of private or internal network available. If you don't want to use NYC2 (or can't get into NYC2—it may be at capacity), you'll definitely want to configure your firewall and any authentication option your services offer. Note that this also means all transit between non-NYC2 instances is billable. If you're moving a lot of data between servers, DigitalOcean may not be as cheap as it initially seems. (You've got a TB to play with even on the cheapest plan but some workloads will chew through that quickly.)

2. Their images are nonstandard in subtle ways. If you're using scripts to bring up servers, either do it manually the first time or pay close attention to any logging output. In general there shouldn't be too many issues. Of particular interest: DigitalOcean images start with a completely empty iptables chain. If your deployment scripts expect the distro vendor's chains to be there, you'll probably end up locked out and have to use the console.

Yeah, I'm a huge fan of the private network instances now. I've been using ubuntu which is a fairly standard root-only server. setting them up goes:

1. Set up user, authorized keys, sudo for that user
2. dist-upgrade, install ufw, vim, other tools needed
3. enable ufw

Takes about 15 minutes now that I know what I'm doing. Could script it out pretty easily.

kayakyakr
Feb 16, 2004

Kayak is true

The Journey Fraternity posted:

select_tag is its own standalone helper method- it isn't called on a form object. Drop the 'f.'

or drop the _tag:

code:
<%= f.select :role, ['professional', 'student'] %>

kayakyakr
Feb 16, 2004

Kayak is true

Newbsylberry posted:

So I'm looking to host a rails4 app, and I'm not really sure what my options are. I am using heroku right now, but it's expensive and I want to use ec2, or elastic beanstalk instead. I followed the steps in this post http://stackoverflow.com/questions/15535140/installing-ruby-2-0-and-rails-4-0-0beta-on-aws-ec2 , and installed ruby and rails on an ec2 instance. I guess I'm not really sure what the next steps are, I think I have to use passenger, and/or nginx? I am having a hard time just figuring out where to start.

if you're using elastic beanstalk, you can use their git plugin to push to ebs. It's not super flexible (ruby 1.9.3, RDS database, passenger w/ embedded nginx, limited options for DNS), but it's almost as easy as heroku: http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_Ruby_rails.html

For a "grown-up" deploy I would suggest learning capistrano, nginx, unicorn or thin or puma, and rvm or rbenv or whatever your preference is. You can deploy that to ec2, linode, digitalocean, or whatever your choice of virtual server is.

kayakyakr
Feb 16, 2004

Kayak is true

Newbsylberry posted:

Awesome, do you have a specific recommendation for one? Or is it just a preference? I use rvm now, so I'm familiar with it.

Edit - Actually I see I'll need to use a combination of them

I use capistrano, nginx, unicorn, and rvm on digital ocean.

Capistrano has plugins for unicorn and rvm and bundler that make it pretty easy to get a server going.

I'm curious about puma, but they say that it's best with jruby and since I use MRI, I've never really tried it.

kayakyakr
Feb 16, 2004

Kayak is true
Do you have a site in sites-enabled? Is it listening to port 80? Is port 80 open in the firewall?

kayakyakr
Feb 16, 2004

Kayak is true
I would go ahead and have your server listen to all:

server_name _;

This will answer all requests which is what you want since you're not going to be hosting any other sites on there.

And that's not your nginx.conf file, right? that should be a file in sites-available named futureoungpros that's symlinked into the sites-enabled directory?

kayakyakr
Feb 16, 2004

Kayak is true

Molten Llama posted:

Data you want to persist is mapped to a database schema, not particularly differently from any other serialization strategy. Though whole objects worth of data are frequently persisted, you don't have to persist all or even any of an object's data.

I'm not trying to be an rear end—this is a conceptual issue I frequently encounter in the wild—but you do realize model classes are just Ruby classes, right? They can (and frequently should) do more than be a thin veneer over ActiveRecord/Mongoid/DataMapper/whatever. Rails doesn't care what else you make that class do. ActiveModel and the mappers implementing it don't care what that class does. Rails doesn't even care if models use a particular mapper (or any mapper) or are persisted at all; if it's in the models directory and it's Ruby code, it's loaded.

Notably, Rails 4 natively autoloads service object classes from a services directory. The modern Rails Way is decomposition and coupling as loose as you can get it.

Good post. Rails is as flexible as you want it to be. Most rails apps people come up with are just front ends to a database schema and so they wind up reflecting the database. This should be a surprise to absolutely no one and I've seen the same setup used in languages and setups that aren't rails written with a lot more code.

Database-wise, ActiveRecord does encourage a pretty decent bit of normalization, and as a SQL guy, I approve of that direction heartily.

kayakyakr
Feb 16, 2004

Kayak is true

Peristalsis posted:

We have a shiny new RoR app with a web interface and a webserivce API for backend access. I want to adapt an old Ruby script (no Rails) to use that API, but it'll be a lot easier if I can use some of the model classes from the web app to do some parsing and processing.

This is a completely different app, running in a different directory (probably even on a different server). Is there a good way to import some of my ActiveRecord models from the Rails app to use in plain Ruby? I really don't want to re-write all the necessary logic.

You can create a gem with those models extracted out. You'll have to require all the necessaries in order to set up ActiveRecord, the database connections, etc for the non-rails app, but it'd be doable.

kayakyakr
Feb 16, 2004

Kayak is true

KoRMaK posted:

I'm trying to incoporate facebook login via omniauth with devise. Users can login via facebook, but it broke the regular devise login. I'm getting a wierd error when a user does the ole devise login
Ruby code:
Started GET "/users/sign_in" for 127.0.0.1 
Processing by Devise::SessionsController#new as HTML
  User Load (0.2ms)  SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 LIMIT 1
Redirected to [url]http://localhost:3001/dashboard[/url]
Filter chain halted as :require_no_authentication rendered or redirected
Completed 302 Found in 2ms (ActiveRecord: 0.2ms)

Filter chain halted as :require_no_authentication rendered or redirected


I have created a sessions_controller.rb that inherits from Devise::SessionsController but it looks like it is not overriding the gemmed version that comes with devise. How do I override the sessions_controller?

I set the routes for it to this


I also have tried overrideing require_no_authentication in the sessions_controller.rb but it never seems to called.

e: drat, I forgot the s in :controllers

What directions are you following for using omniauth with devise? I have a working devise + omniauth (for facebook, google, etc) and I don't have my sessions controller overridden.

The only things I've done is add an ominauth callbacks controller and the configuration to config/initializers/devise.rb

kayakyakr
Feb 16, 2004

Kayak is true

That's the one.

kayakyakr
Feb 16, 2004

Kayak is true

KoRMaK posted:

Sweet, I have devise and facebook login working side by side. I had to override registrations and sessions to handle the two properly.

New question: how do I keep heroku from taking forever when doing the assets:precompile step? I added ckeditor to my vendor/javascripts folder and I am pretty sure that is what is taking it so long. I never change the files in that directory, so why does it precompile on each push? I want it to only precompile if there are differences.

In case anyone here wants to check out what I've been working on, you can find it at http://marquee.liquid-software.com It lets you create conversation threads connected to any gps location. Kind of like yelp, but instead of being tied to a business you can tie it to any arbitrary location.

try:
https://github.com/ndbroadbent/turbo-sprockets-rails3

kayakyakr
Feb 16, 2004

Kayak is true
Programming in Ruby helped me decide to make the permanent switch to Linux. Haven't looked back.

kayakyakr
Feb 16, 2004

Kayak is true

foutre posted:

Apologies if this is the wrong place to ask this. I have basically no knowledge of programming (like, I knew Java and Visual Basic in middle school, but haven't programmed in the last seven years). Now though, I want to make a web-app (I think) that would basically just let people submit forms on a site, and then spit out a generic email response.

I have a good three months to do this, and want to figure it out myself. Would Ruby on Rails be a good way of doing this, and if so, what are some good resources for getting started?

At the moment I'm using codeacademy's Ruby track, that teaches poo poo like "what the hell does && do". I'm also taking CS 101 online from Stanford, that is basically "what is a program". Beyond that though, I'm not sure how to best go about teaching myself. Should I get a dummies book? Are there online resources I'm missing? I'd love help, thanks a lot.

Ruby on Rails is indeed a good language for what you want to do. Fairly easy to learn and has a good bit of hand-holding for beginners once you grasp a few concepts of the Rails conventions.

I used O'Reilly Rails Cookbook for my first book, but I'm more of a get it started and learn as I go kind of person, so I moved beyond the book pretty quickly.

There should be some other suggestions coming shortly, though.

kayakyakr
Feb 16, 2004

Kayak is true

raej posted:

Well, as a proof of concept with bogus data entries, I have the web app up and running on Heroku.

One thing I'm facing now is that to go live, I'll need to import my beer data set into the database. This means ~200,000 unique beers and ~14,000 breweries. This puts me into two options with Heroku:

1) $9/month - Hobby databases are designed for trial, development, testing, and basic usage for hobby apps. Hobby databases are not suited for production. Up to four hours of downtime per month.
2) $200/month - Tengu - 1.7GB RAM - 256GB storage - 200 connections

That escalates quickly.

Are the other hosting options for long but not wide databases?

They have another tier under standard for $50/month. But in all honesty, you could probably use their hobby level $9 database and be ok.

Other options:
- There's a heroku add-on that will give you a 1GB mysql db with claimed 100% uptime for $10/month.
- Could use AWS free tier for their sql-style database (think it has a 250 MB allowance).
- Could set up a $5/month small instance on DigitalOcean, install your own database, and open it up to connections from Heroku.

kayakyakr
Feb 16, 2004

Kayak is true

Nybble posted:

I would recommend this highly. DigitalOcean is phenomenal.

(Heck, you could just put your app there, too.)

I do enjoy a full stack server for $5, 2 cores for $20.

kayakyakr
Feb 16, 2004

Kayak is true

Mystery Machine posted:

I've recently gotten into Rails, and I wanna put an app up on JustHost. I tried for a while, but completely fell flat. Does anyone have a step by step guide on how to set up a Rails app on that service? Or another hosting service? I tried a bunch of things, but had an incredibly off putting time. I'm assuming I'm the one who royally hosed up, but really weird things were going on. Like, I accessed the command line for the hosting, and I couldn't do things as a super user. I couldn't apt-get anything, just a bunch of weirdness.

In short, I'm excited to build a site for a friend using Rails, and while I can use Rails just fine locally on my computer, I'm completely at a loss on how to do it on my friend's hosting. Can anyone point me in the right direction?

Don't do it on your friend's hosting. His hosting is awful. It's seriously not even worth the pain of trying.

I would suggest going here first because free server, super easy:
https://www.heroku.com/

That will work for you, but if you insist on being different, I'd suggest going here:
https://www.openshift.com/

If you really want to futz with servers, then yes, launch a $5 server on https://www.digitalocean.com

But really, for your level, Heroku will get you up and running fastest.

kayakyakr
Feb 16, 2004

Kayak is true

The Journey Fraternity posted:

You can get around that by adding the free tier of New Relic. It can be configured to use a heartbeat URL to determine if the server is still up. Since it pings the server more frequently than the dyno sleep time, it'll never sleep.

This is pretty brilliant.

kayakyakr
Feb 16, 2004

Kayak is true

prom candy posted:

That's not really sustainable though, I think Heroku's free tier only works if people aren't artificially keeping their apps alive.

And all of this is why, outside of a hobby app (where it's ok that it takes 10s to launch), you should look into alternatives like digital ocean and openshift (not sure about openshift's capabilities, had just started looking at it).


In other news, I've been playing with the new capistrano, version 3, today. They changed a lot of the way it works, but now that I'm getting the hang of how it WANTS to do things, I'm finding that it's really, really powerful. Like it very much.

kayakyakr
Feb 16, 2004

Kayak is true

Obsurveyor posted:

That's not how businesses able to offer a free tier work. You will see the free tier quickly be replaced or the hours reduced if every free account starts using every single dyno hour of a month.

Dunno, Heroku is about as mature as a company that sprang up from rails gets. If they were going to remove their free tier, you'd think they'd have done it by now. They make conversions because the single dyno is rarely ever enough for a mature app (and as mentioned before, they put inactive dynos to sleep). If someone uses their full free tier monthly then so be it.

kayakyakr
Feb 16, 2004

Kayak is true

prom candy posted:

Yeah and what we're discussing is tricking Heroku into thinking your dyno is active in order to not get it put to sleep. If everyone was to keep their free-tier dynos active at all times they wouldn't be able to offer the free-tier.

But everyone doesn't and so it's not an issue, no? It's a neat workaround for sites that get little enough traffic that they go into standby mode but are critical enough that a delay on the first load when someone does use it would be a significant issue.

There aren't many sites like that, really. Maybe an early, small startup that might get 10-15 organic visits/day and needs a high conversion? But still, that's not what you'd use Heroku for anyway.

Is it a big deal?

kayakyakr
Feb 16, 2004

Kayak is true

raej posted:

Is there a good way to practice before buying in? Just set up an old box and install debian?

Or just do something like this? https://www.digitalocean.com/community/articles/how-to-use-the-digitalocean-dokku-application

Or you can use Amazon's free tier to get a year's worth of an EC2 micro server. Use an ubuntu image and roll with it.

When I build my servers, I have a few steps along the way:

1: Set up the user
Digital Ocean's bare Ubuntu distros (I like to use 12.04x64 for "production" servers, which I'll upgrade to 14.04 next year, will play with other versions) come set up with just a root user out of the box. I like the way that the EC2 server looks when set up, so I emulate that.

Logged in as root:
code:
useradd -m -s /bin/bash ubuntu -G sudo
mkdir /home/ubuntu/.ssh
cp ~/.ssh/authorized_keys /home/ubuntu/.ssh/authorized_keys
chown ubuntu:ubuntu /home/ubuntu/.ssh -R
visudo
Add "ubuntu ALL (ALL:ALL) NOPASSWD: ALL" to the sudoers file and save.

2: Prep for server

Exit, log in as ubuntu, and run:
code:
sudo bash -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main" >> /etc/apt/sources.list.d/pgdg.list'
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get install nginx postgresql-9.3 libpq-dev
sudo ufw allow ssh
sudo ufw allow http
sudo ufw enable
You should set up your postgres server now:
Bash code:
sudo su - postgres
psql
CREATE ROLE ubuntu WITH LOGIN;
CREATE DATABASE application_production WITH OWNER ubuntu;
\q
exit
3: Capify
I use capistrano for doing my deploys. Out of the box it does a whole lot of work for you.


This is my list of gems for capistrano:
Ruby code:
gem 'capistrano', :require => false
gem 'capistrano-rails', :require => false
gem 'rvm1-capistrano3', :require => false
gem 'capistrano3-unicorn', :require => false
I also use figaro for my environment variables.

These are the important changes I make to my deploy.rb script that took me a while to figure out (the remote file thing that is):
code:
set :deploy_to, "/home/ubuntu/#{fetch(:application)}"

set :linked_files, %w{config/application.yml}
set :linked_dirs, %w{log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}

set :keep_releases, 5

set :rvm1_ruby_version, '2.0.0-p353'

set :unicorn_pid, -> { File.join(shared_path, "tmp", "pids", "unicorn.pid") }

namespace :deploy do  
  desc 'Restart application'
  task :restart do
    invoke 'unicorn:restart'
  end
  
  namespace :check do
    task :linked_files => shared_path.join('config/application.yml')
  end
end

remote_file shared_path.join('config/application.yml') => 'config/application.yml', roles: :app

file 'config/application.yml' do |t|
  on roles(:app) do |host|
    upload! t.name, shared_path.join(t.name)
  end
end
That's not the whole file, but it's enough of it, you should be able to figure out the rest. You also need to required all the gems you added in Capfile:
code:
require 'capistrano/bundler'
require 'capistrano/rails'
require 'rvm1/capistrano3'
require "whenever/capistrano"
require "capistrano3/unicorn"
Set your server in config/deploy/production.rb

4: Unicorn
You have to configure unicorn, I suggest like so:
code:
# Set your full path to application.
app_path = "/home/ubuntu/application/current"

# Set unicorn options
worker_processes 2
preload_app true
timeout 180

# Spawn unicorn master worker for user apps (group: apps)

# Fill path to your app
working_directory app_path

listen "#{app_path}/tmp/sockets/unicorn.sock", :backlog => 64

# Should be 'production' by default, otherwise use other env
rails_env = ENV['RAILS_ENV'] || 'production'

# Log everything to one file
stderr_path "log/unicorn.log"
stdout_path "log/unicorn.log"

# Set master PID location
pid "#{app_path}/tmp/pids/unicorn.pid"

before_fork do |server, worker|
  defined?(ActiveRecord::Base) and ActiveRecord::Base.connection.disconnect!

  # Before forking, kill the master process that belongs to the .oldbin PID.
  # This enables 0 downtime deploys.
  old_pid = "tmp/pids/unicorn.pid.oldbin"
  if File.exists?(old_pid) && server.pid != old_pid
    begin
      Process.kill("QUIT", File.read(old_pid).to_i)
    rescue Errno::ENOENT, Errno::ESRCH
      # someone else did our job for us
    end
  end
end

after_fork do |server, worker|
  defined?(ActiveRecord::Base) and ActiveRecord::Base.establish_connection
end
5: Deploy
Locally run "cap production deploy --trace" handle any issues that come up. I had a few.

6: Nginx
Back on the server, add something like this to /etc/nginx/sites-available/application:
code:
upstream application_rails{
  server unix:/home/ubuntu/application/current/tmp/sockets/unicorn.sock fail_timeout=0;
}

#server {
#  listen 80;
#  server_name _;
#  return 301 https://application.com$request_uri;
#}

server {
  listen 80;

#  ssl on;
#  ssl_certificate /etc/ssl/certs/application.com.combined.crt;
#  ssl_certificate_key /etc/ssl/certs/application.com.key;

  server_name _;

  root /home/ubuntu/application/current/public;
  index index.html;
  try_files $uri.html $uri @app;

  location ~ ^/assets/ {
    gzip_static on;
    expires max;
    add_header Cache-Control public;
  }  

  location @app {
    # If the file exists as a static file serve it directly
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto http;
    proxy_set_header Host $http_host;
    proxy_redirect off;

    # Oh yeah, hand over the request to Rails! Yay! :-D
    proxy_pass http://application_rails;
  }
}
And honestly there's probably something I'm doing poorly in there. That also includes, commented out, how you would use SSL.

Also on the server do:
code:
sudo ln -s /etc/nginx/sites-available/application /etc/nginx/sites-enabled/application
sudo rm /etc/nginx/sites-enabled/default
sudo service nginx restart
7: Done
Seriously, sit back and open a beer, you just became capable of doing devops using Digital Ocean. Hit your website and rejoice.

kayakyakr fucked around with this message at 21:59 on Dec 16, 2013

kayakyakr
Feb 16, 2004

Kayak is true

Smol posted:

After you manually set up servers a couple of times like that though, start using some kind of configuration management tool, like Puppet or Chef. Makes setting up new boxes from scratch truly a one click affair.

Yeah, if you find yourself doing that a lot, I would look into puppet or chef or maybe just write yourself a custom capistrano task that does it all for you.

But really, the part that Puppet/Chef handles takes me about 3 minutes to do after the server's been spun up, and outside of horizontal scaling how often do you have to perform an initial server configuration? Most of the first half of that post was done by memory (other than copy/pasting postgres's apt repo) and the rest was copy/pasted from my most recent project. It'd take years to have the time for a puppet/chef setup equal the time used typing into terminals.

kayakyakr
Feb 16, 2004

Kayak is true
yeah, yeah, double posting, but what would you guys think about starting a new thread? The OP is from over 6 years ago, everything in it is horribly out of date, the poster hasn't posted here since 2008, and with a 122 page thread, the same questions have tended toward being asked many times already.

I'm thinking: OP would have resources, links to tutorials, and suggestions for setting up an environment. Probably mention hosting. A 2nd post would be a copy of my Digital Ocean deploy tutorial above.

Thoughts? Anything that'd need to be in the first set of posts that you'd like to see such as suggested gems or whatnot?

kayakyakr
Feb 16, 2004

Kayak is true

Oh My Science posted:

Yeah, I did the same thing with the web dev thread and it's a pretty solid OP now. I used google docs and let the frequent posters edit or create new content, which worked well as a collaborative approach.

Do you just have a copy of the OP off in some google drive doc and you copy/paste update it every once in a while?

I think that guides and the like can be linked to from the OP. So you'd create a guide, and then the link to it and description would go in the OP.

I'll get that started. Google Doc. Gonna use this as the basis. For now I'm going to go ahead and allow open access to editing, but maybe in the future lock it down to people that request editing access?

kayakyakr
Feb 16, 2004

Kayak is true

Oh My Science posted:

Dare I suggest we make the thread about ruby frameworks and not just rails?

Oh my. That would be out there. I think that would be good, though. Ruby + frameworks.

e: editing open now.

kayakyakr
Feb 16, 2004

Kayak is true

Oh My Science posted:

FYI don't go too crazy the with the internal guides and instead point to external documentation or blogs. I would say 90% of the commonly used frameworks and deployment tools have decent documentation now anyway.

Right. But things like the above deployment guide would be good, I would think, because it could stand on its own as a blog post. If I had the time/inspiration to maintain a blog, that post would have been there and linked to here.

But I'd rather spend my time with you guys, so it's an exclusive. Screw the Internet at large.

kayakyakr
Feb 16, 2004

Kayak is true

Dangerllama posted:

To bring this back to your original point, though, you are very correct: Use a configuration management system to build boxes. It's all well and good to say "I can just install nginx and unicorn and such by hand. It's so much quicker." But you will eventually either a) forget how you built said box, or more probably b) stop caring. It's important you provide someone else with the ability to replicate your work. Even if it's just future you.

Just because I enjoy playing devil's advocate, you do run a risk, if you rely on a configuration manager, that it goes out of flavor 1-2 years down the road and now you're locked into a configuration app that lacks support, lacks community involvement, and has been replaced by the new flavor of the month.

Ansible came out last year. Chef in '09. Puppet is mature at '05. I hadn't even heard of Sprinkle. Then there's Docker/dokku that's just gaining traction and other "transportable environments." You can really get analysis paralysis looking at all these toolkits. Just be careful that you don't spend more time on deployment tools than you spend on development.

The takeaway: learn how to do it yourself and once you can, do whatever the hell feels comfortable to you, be it using a configuration manager or continuing to do it by hand.

This conversation completely changes in a large team environment. I would use a configuration manager there so you can get a consistent server with some guarantee of idiot-proofing.

kayakyakr
Feb 16, 2004

Kayak is true

Newbsylberry posted:

I know this thread is on its way out, but I was curious if anyone had used this guide to set up devise/omniauth for rails4: https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview ? I know Kayakyakr recommended it earlier in the thread, but I couldn't get it to work in rails4. I am reinstalling devise and having another run, but if anyone knows of any issues or concerns I might run into I would love the help.

Didn't get to work on the new thread over the break.

That should be working with rails 4, is there anything in particular that it's giving you an issue with?

kayakyakr
Feb 16, 2004

Kayak is true

Newbsylberry posted:

I am getting the pretty common error:

Authentication Failure! invalid_credentials: OmniAuth::Strategies::OAuth2::CallbackError, OmniAuth::Strategies::OAuth2::CallbackError

I have tried setting omniauth-facebook at version 1.4, and some of the other common solutions seen on Stack Overflow, but they aren't working for me.

Edit - I am also wondering if people have a certain "protocol" they follow for writing methods or code they aren't familiar with (everything for me) in order to make it more manageable and possible to break it into parts?

I've had issues with facebook's oauth and working with my localhost, could that be something? I know that it isn't a Rails 4 issue as I have omniauth and devise working fine.

Maybe try debugging in your callback and see what facebook is sending you?

Adbot
ADBOT LOVES YOU

kayakyakr
Feb 16, 2004

Kayak is true

raej posted:

Rails generates a 404.html file to use for all 404 errors. Is there a good way to get this file to use bootstrap? I'd like it to have the same look and feel as the rest of the site without adding a lot of bloat/redundant styling.

You could use a rescue_from in your application controller to go ahead and render a 404 using your application layout. Something like this:

https://gist.github.com/Sujimichi/2349565

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply