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
hmm yes
Dec 2, 2000
College Slice
You're not going to hear me argue that it isn't cheaper or that it doesn't give better performance, I just misunderstood the pricing when I first made my post. I thought I could pay for 10 apps on 1 DO server + 1 cloud66 subscription, when it would actualy be 10 apps on 10 DO servers + 10 cloud66 subscription. Both options are cheaper than Heroku, but also mean you have to take care of a VPS (initial magical setup aside).

Despite my last post I'm still convinced the value Heroku provides as a managed service means that it is still a good choice despite less expensive alternatives.

We use the workless gem to scale Heroku workers up and down as needed, which also lets us burst up to 10+ workers at a time to breeze through heavy background processing. Since workers are mostly idle it means we pay a few dollars per month for this. It does mean there is a ~20s delay for any background job to start while a new worker instance spins up, but it gives you background jobs on Heroku for much less than $36/mo.

hmm yes fucked around with this message at 04:13 on Sep 7, 2013

Adbot
ADBOT LOVES YOU

DreadCthulhu
Sep 17, 2008

What the fuck is up, Denny's?!
Very lazy question: does Rails do a detailed logging of SQL queries in production mode, similar to what it looks like in development? Or actually, even better, does Rails log at different levels depending on RAILS_ENV?

enki42
Jun 11, 2001
#ATMLIVESMATTER

Put this Nazi-lover on ignore immediately!

DreadCthulhu posted:

Very lazy question: does Rails do a detailed logging of SQL queries in production mode, similar to what it looks like in development? Or actually, even better, does Rails log at different levels depending on RAILS_ENV?

By default I think production logs at a fairly high level (maybe warn? I could be wrong on this), but you can change your log level by changing config.log_level inside the appropriate environment file (in this case, production.rb). SQL queries would be on the info level, I think.

If you're on Heroku, I think you might still need to do some magic to get the Rails logger to log to STDOUT and heroku logs to pick it up.

Molten Llama
Sep 20, 2006

enki42 posted:

By default I think production logs at a fairly high level (maybe warn? I could be wrong on this), but you can change your log level by changing config.log_level inside the appropriate environment file (in this case, production.rb). SQL queries would be on the info level, I think.

At least in 4, production defaults to info and queries are limited to debug.

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder
Wow ajax/javascript integration testing is extremely frustrating.

I pretty much only have one model with more than a trivial amount of ajax/javascript, and both selenium-chrome, selenium-firefox, and capybara-webkit all have different problems, unrelated problems that don't exist on a real browser.

It's not even async problems, I've got those mostly worked out. It's things like the browser trying to click on buttons off screen (and failing), or z-index issues making buttons unclickable.

DONT THREAD ON ME fucked around with this message at 05:57 on Sep 9, 2013

blugbee
Mar 1, 2004
hi c-fut
Does anyone know how to validate multiple unsaved nested attributes against each other?

I have a model "Event" which accepts nested attributes for "Timeslot". I'm using the cocoon gem to allow the for the creation of multiple nested "Timeslots" in the "Event" form.

For example
"Event A"
Timeslot 1 08:00 - 10:00
Timeslot 2 13:00 - 15:00
Timeslot 3 16:00 - 16:45
Timeslot N ......

I want to validate that none of the nested timeslots have overlapping time intervals, but I don't know how to access other "unsaved" timeslot from within the Timeslot model.

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder
This is how I deal with problems like that. It's not very "rails" but my code got way, way cleaner when I stopped using callbacks that do anything more than change the internal state of the model. I've never used :accepts_nested_attributes though so I don't know much about it.

http://samuelmullen.com/2013/05/the-problem-with-rails-callbacks/

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

chumpchous posted:

Wow ajax/javascript integration testing is extremely frustrating.

I pretty much only have one model with more than a trivial amount of ajax/javascript, and both selenium-chrome, selenium-firefox, and capybara-webkit all have different problems, unrelated problems that don't exist on a real browser.

It's not even async problems, I've got those mostly worked out. It's things like the browser trying to click on buttons off screen (and failing), or z-index issues making buttons unclickable.

Is the JS modular and DOM-independent enough that you can use something like jasmine to unit test it?

Peristalsis
Apr 5, 2004
Move along.
I'm really trying to use the built-in testing stuff for the new RoR project at work, and I can't figure out why it won't do what it's supposed to do.

I've put a dummy test in a single model class's unit test, and I just want to run the drat thing.

I've tried running this from rake, directly with ruby, with and without the -I switch (I probably have the wrong syntax for that) to capture 'test_helper', etc. The closest I come is when I get an error that a column isn't in a table. That's a true statement, but I've run a migration that deleted it, and I don't have a clue how or why the test still thinks it should be there. I'm doing development on my Windows machine, using SQLite3, if that matters. I have a Linux VM, but I'm waiting for our helpdesk to get with me to get the database set up on that appropriately, so for now, I'm stuck with Windows 7.

So, here are my questions:

1) I just want to run a single file's tests - what is the syntax for that (including the -I switch, if I need it)? I just have the default rails directory structure, with a test directory below the main app directory, and test files stubbed in by the scaffolding. I've found lots of weird and inconsistent suggestions online, none of which work for me. The best single instruction set glosses over the switch. I've been trying things on the order of "rake test <my path and file>", and I sometimes throw in a "-I <directory>" for good measure.
2) For the -I switch, some of the sources I found seem to put quotes around the path, and not leave a space after the switch but before the path - is that right?
3) What testing method does this default rails project testing use? These look like Test::Unit tests, but just running them from the command line as such doesn't work. I don't think they're Rspec, since they don't look like that syntax, but I guess I could be wrong.

Sub Par
Jul 18, 2001


Dinosaur Gum
I'm building a simple search form and trying to determine if this approach is safe from an SQL injection point of view:
code:
@users = User.where("username like ?","%#{params[:search]}%")
I can't seem to find an answer that's on point. Is there a better/safer way to accomplish this?

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder

Cocoa Crispies posted:

Is the JS modular and DOM-independent enough that you can use something like jasmine to unit test it?

Unfortunately no. Most of my JS comes from gems or is so simple that it doesn't really need to be tested, I'm really only testing the JS elements implicitly. It's just that (one of my more important) views has a lot of ajax going on and I can't test it unless I'm in a JS capable webdriver.

Peristalsis
Apr 5, 2004
Move along.
Oh, and one more question.

I think this came up with a one-to-many relationship between two models/tables, say owners and products (one owner can own many products).

If I create a new product object, and add it to an owner like this "owner1.products << my_new_product_object", then I can see the product in the products array, the next time I execute "owner1.products". However, if I just manually set "my_new_product_object.owner_id = 1", then Rails doesn't add it to owner1.products, even though, as far as I know, the net effect should be exactly the same.

Any idea what's going on here?

Molten Llama
Sep 20, 2006

Peristalsis posted:

1) I just want to run a single file's tests - what is the syntax for that (including the -I switch, if I need it)?

Unless you're working with a plain old Ruby object, you probably need a Rails environment anyway, so don't bother with running Ruby itself or worrying about the -I argument. Start with the standard rake test, then tack on TEST=path/to/test:
code:
rake test TEST=test/models/my_fancy_active_record_model_test.rb
Short of something being incredibly wrong with your environment, that'll do it.

quote:

2) For the -I switch, some of the sources I found seem to put quotes around the path, and not leave a space after the switch but before the path - is that right?

Doesn't matter, at least on POSIX operating systems. You need quotes or backslash escaping if there are spaces (or other special characters) in the path; you don't need quotes if there are no special characters. The way arguments are handled by Ruby and many UNIXy utilities, spaces between arguments and their parameters aren't mandatory.

YMMV in a Windows environment with some tools, but Ruby itself should behave consistently.

quote:

3) What testing method does this default rails project testing use? These look like Test::Unit tests, but just running them from the command line as such doesn't work. I don't think they're Rspec, since they don't look like that syntax, but I guess I could be wrong.

Test::Unit (or minitest if it's available).

Sub Par posted:

I can't seem to find an answer that's on point. Is there a better/safer way to accomplish this?

Is this a query you need to run a lot? If so, and you're running Postgres, pg_search would allow you to kick the speed up a ton and give you all kinds of features like fuzzy matching.

Molten Llama fucked around with this message at 21:04 on Sep 9, 2013

Peristalsis
Apr 5, 2004
Move along.

Molten Llama posted:

Unless you're working with a plain old Ruby object, you probably need a Rails environment anyway, so don't bother with running Ruby itself or worrying about the -I argument. Start with the standard rake test, then tack on TEST=path/to/test:
code:
rake test TEST=test/models/my_fancy_active_record_model_test.rb

Thanks. If I change that to
code:
rake test TEST=test/unit/model_test.rb
the test tries to run, but I still get this weird error about the table not having a name column. Again, that's true, the name column was removed with a migration, but it's NOT for the table associated with the model I'm testing, and I don't know why or how rake/Rails thinks it needs to try to insert a name column into that table (or why it's trying to insert anything at all, for that matter):

code:
ActiveRecord::StatementInvalid: SQLite3::SQLException: table channels has no column named name: INSERT INTO "channels" ("name", 
"description", "organism", "source", "strain", "growth_medium", "growth_stage", "material_type", "replicate_type", "label", 
"pmt", "channel_number", "created_at", "updated_at", "id") VALUES ('MyString', 'MyText', 'MyString', 'MyString', 'MyString', 
'MyString', 'MyString', 'MyString', 'MyString', 'MyString', 'MyString', 1, '2013-09-09 20:01:10', '2013-09-09 20:01:10', 
980190962)

Peristalsis fucked around with this message at 21:20 on Sep 9, 2013

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

Peristalsis posted:

Thanks. If I change that to
code:
rake test TEST=test/unit/model_test.rb
the test tries to run, but I still get this weird error about the table not having a name column. Again, that's true, the name column was removed with a migration, but it's NOT for the table associated with the model I'm testing, and I don't know why or how rake/Rails thinks it needs to try to insert a name column into that table (or why it's trying to insert anything at all, for that matter):


You have some fixtures that need updating (or rather, deleting and replacing with Factory Girl).

kayakyakr
Feb 16, 2004

Kayak is true

Sub Par posted:

I'm building a simple search form and trying to determine if this approach is safe from an SQL injection point of view:
code:
@users = User.where("username like ?","%#{params[:search]}%")
I can't seem to find an answer that's on point. Is there a better/safer way to accomplish this?

That should be ok. The cleaner will clean the full string out. If you get anything more complex than that, you should really look into integrating sphinx.

Peristalsis posted:

Oh, and one more question.

I think this came up with a one-to-many relationship between two models/tables, say owners and products (one owner can own many products).

If I create a new product object, and add it to an owner like this "owner1.products << my_new_product_object", then I can see the product in the products array, the next time I execute "owner1.products". However, if I just manually set "my_new_product_object.owner_id = 1", then Rails doesn't add it to owner1.products, even though, as far as I know, the net effect should be exactly the same.

Any idea what's going on here?

Did you reload owner1 between creating your new product object? Otherwise, it'll probably just cache the last products lookup. Are you use the product object is saving and are you sure that's the proper id?

Sub Par
Jul 18, 2001


Dinosaur Gum

kayakyakr posted:

That should be ok. The cleaner will clean the full string out. If you get anything more complex than that, you should really look into integrating sphinx.

Thanks. I plan to, once I can spend some money.

kayakyakr
Feb 16, 2004

Kayak is true

Sub Par posted:

Thanks. I plan to, once I can spend some money.

what are you hosting on? we successfully ran sphinx + thinking_sphinx (rails gem) side-by-side with unicorn on a single virtual server.

Sub Par
Jul 18, 2001


Dinosaur Gum

kayakyakr posted:

what are you hosting on? we successfully ran sphinx + thinking_sphinx (rails gem) side-by-side with unicorn on a single virtual server.

I have a proof of concept type thing up on Heroku and am just trying to drum up interest in the idea. If I can get my friends on board and put up a small amount of cash I am going to go with a VPS, but Heroku for now. Not worth even the $12/mo for the sphinx-based add-ons right now for my ~600 users.

kayakyakr
Feb 16, 2004

Kayak is true

Sub Par posted:

I have a proof of concept type thing up on Heroku and am just trying to drum up interest in the idea. If I can get my friends on board and put up a small amount of cash I am going to go with a VPS, but Heroku for now. Not worth even the $12/mo for the sphinx-based add-ons right now for my ~600 users.

~600 users is not bad for a proof of concept on heroku. I know a lot of people hate it, but you could get a 2 core, 40 GB VPS on digital ocean for $20/month.

enki42
Jun 11, 2001
#ATMLIVESMATTER

Put this Nazi-lover on ignore immediately!

Sub Par posted:

I'm building a simple search form and trying to determine if this approach is safe from an SQL injection point of view:
code:
@users = User.where("username like ?","%#{params[:search]}%")
I can't seem to find an answer that's on point. Is there a better/safer way to accomplish this?

Nope, you're good. params[:search] could have SQL injection stuff, but the ? prevents any of it from being treated as executable SQL code.

Peristalsis
Apr 5, 2004
Move along.

Cocoa Crispies posted:

You have some fixtures that need updating (or rather, deleting and replacing with Factory Girl).

Thanks - I didn't even know fixtures existed. I'm googling around, but not seeing any information on how to maintain them. Are migrations supposed to update fixtures automatically, or am I supposed to go change them by hand every time my data def changes? Is there a Rails command to recreate them all from scratch?

Obsurveyor
Jan 10, 2003

Peristalsis posted:

Thanks - I didn't even know fixtures existed. I'm googling around, but not seeing any information on how to maintain them. Are migrations supposed to update fixtures automatically, or am I supposed to go change them by hand every time my data def changes? Is there a Rails command to recreate them all from scratch?

No, you have to maintain them. Ideally, you only use FactoryGirl during integration/acceptance testing and never for your unit tests. You don't want to have to spin up the full stack for unit tests anyway, it's way too slow.

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

kayakyakr posted:

That should be ok. The cleaner will clean the full string out. If you get anything more complex than that, you should really look into integrating sphinx.

Sub Par posted:

I have a proof of concept type thing up on Heroku and am just trying to drum up interest in the idea. If I can get my friends on board and put up a small amount of cash I am going to go with a VPS, but Heroku for now. Not worth even the $12/mo for the sphinx-based add-ons right now for my ~600 users.

If you're on Heroku, you can use Postgres full-text search instead. I've used https://github.com/Casecommons/pg_search on Heroku, and it works well without having to manage yet another database server.

Sub Par
Jul 18, 2001


Dinosaur Gum
Sweet, I'll look into that. Thanks.

I'm intrigued by the pricing of DigitalOcean and Linode. Anyone have a guide handy that can help walk me through migrating from Heroku to either of these? I'm starting to get frustrated with the add-on situation (add-on for email, monthly fees for SSL, poo poo like that). Thanks.

Smol
Jun 1, 2011

Stat rosa pristina nomine, nomina nuda tenemus.
Start with a vagrant + puppet/chef/whatever configuration for your app. That's probably the hardest part.

kayakyakr
Feb 16, 2004

Kayak is true
I learned how to use capistrano not too long ago so setting up a new environment from scratch with that is two commands and about 10 minutes.

ignore the other horrible code in this project, this is a simple capistrano deploy script:
https://github.com/Yakrware/sum_times/blob/master/config/deploy.rb
plus
https://github.com/Yakrware/sum_times/blob/master/config/deploy/production.rb.example

in others I've got it installing requirements in the setup and you can script it to set up nginx or whatever you need.

Sil
Jan 4, 2007
I come looking for inspiration!

Background: Small, single admin(not a programmer, needs wysiwyg), CMS application. ActiveAdmin interface for the admin(not essential but nice to have). Write articles, send a newsletter, post links to a facebook page referencing the articles. Also publish the articles to a blog(which has most basic blog features, tags, search, archive, like buttons, FB JS thingy for comments, pagination etc). Currently deployed to a free Heroku Dyno.

Problem: Currently deployed to a free Heroku Dyno. I would like to serve static html outside of the ActiveAdmin interface(ie the public blog part) since the DB will change once a day or less. Sadly page caching seems to be a huge pain with Heroku and every other cache option still unnecessarily touches the application.

Question: Anyone got ideas for how to serve the blog statically for non-admin visitors, while staying free and as easyish to deploy as heroku is and while keeping the Admin interface?

At the moment, I'm wondering if I can kludge together the Heroku app so that it uses octopress for the front end blog and still runs the activeadmin app for the /admin backend. I'm not even sure what that means right now.

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

Sil posted:

Question: Anyone got ideas for how to serve the blog statically for non-admin visitors, while staying free and as easyish to deploy as heroku is and while keeping the Admin interface?

At the moment, I'm wondering if I can kludge together the Heroku app so that it uses octopress for the front end blog and still runs the activeadmin app for the /admin backend. I'm not even sure what that means right now.

Not without going way off the reservation.

You could do it by having changes on the admin end re-render the entire site and upload it to S3, but that's a pain in the rear end, and if you value your time at all, way more expensive than just keeping a dyno live all the time.

A MIRACLE
Sep 17, 2007

All right. It's Saturday night; I have no date, a two-liter bottle of Shasta and my all-Rush mix-tape... Let's rock.

Sil posted:

I come looking for inspiration!

Background: Small, single admin(not a programmer, needs wysiwyg), CMS application. ActiveAdmin interface for the admin(not essential but nice to have). Write articles, send a newsletter, post links to a facebook page referencing the articles. Also publish the articles to a blog(which has most basic blog features, tags, search, archive, like buttons, FB JS thingy for comments, pagination etc). Currently deployed to a free Heroku Dyno.

Problem: Currently deployed to a free Heroku Dyno. I would like to serve static html outside of the ActiveAdmin interface(ie the public blog part) since the DB will change once a day or less. Sadly page caching seems to be a huge pain with Heroku and every other cache option still unnecessarily touches the application.

Question: Anyone got ideas for how to serve the blog statically for non-admin visitors, while staying free and as easyish to deploy as heroku is and while keeping the Admin interface?

At the moment, I'm wondering if I can kludge together the Heroku app so that it uses octopress for the front end blog and still runs the activeadmin app for the /admin backend. I'm not even sure what that means right now.

Re-render the static pages at <time_interval> using a rake task hooked up to Heroku's cron plugin? Then just render them on command if is_admin? in the controller?

Pardot
Jul 25, 2001




A MIRACLE posted:

Re-render the static pages at <time_interval> using a rake task hooked up to Heroku's cron plugin? Then just render them on command if is_admin? in the controller?

This will not work. The scheduler add-on spins up a fresh dyno, runs the command, then throws away the dyno. It just runs `heroku run:detached <cmd>` on your behalf every (day|hour|10 minutes).

DreadCthulhu
Sep 17, 2008

What the fuck is up, Denny's?!
Rails migrations are by default wrapped into a transaction, correct?

KoRMaK
Jul 31, 2012



I want to host a portfolio app thats just a small demo of an idea on the Internet for as cheap as possible. It seems like heroku might have a free option. Am I understanding that correctly?

KoRMaK fucked around with this message at 05:41 on Sep 15, 2013

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.

KoRMaK
Jul 31, 2012



kayakyakr posted:

e: ^^^ github pages are also good for static apps. It's http://nestacms.com/ on the back end if i'm not mistaken.
Is this in regards to my question? My app isn't going to be static.

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!

ufarn
May 30, 2009
Never was a Ruby person, but I have to use it for a project, and I'm getting some errors in Homebrew and RVM. From another thread:

ufarn posted:

I get two errors from rvm, when I try to update my version of Ruby: an Xcode version error and a permission error.

Since my Xcode version is newer than the log suggests, and since I am logged in as the main admin account, I can't make sense of the error message.

The full message is available here with some added commands thrown in to highlight the problem.

ufarn posted:

The CLI tools are up-to-date, and I tried the FAQ, but `brew doctor` shows a bunch of issues I don't know enough about OS X and CLI work to make sense of.

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

ufarn posted:

Never was a Ruby person, but I have to use it for a project, and I'm getting some errors in Homebrew and RVM. From another thread:
Is RVM up to date?

The nuclear option is always there: rvm implode and switch to rbenv & ruby-build.

ufarn
May 30, 2009

Cocoa Crispies posted:

Is RVM up to date?

The nuclear option is always there: rvm implode and switch to rbenv & ruby-build.
Updating rvm and running sudo rvm upgrade 2.0.0 allowed me to upgrade Ruby, but the bundle command isn't recognized. Think it involves playing with my env vars.

More for me to look into at a later point, I guess.

Adbot
ADBOT LOVES YOU

Smol
Jun 1, 2011

Stat rosa pristina nomine, nomina nuda tenemus.
gem install bundler

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