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
Paul MaudDib
May 3, 2006

TEAM NVIDIA:
FORUM POLICE
What's the safest way to get a reasonably-up-to-date and version-matched build of Ruby and Rails in Ubuntu? apt-get install ruby rubygems, then gem install rails, then use rvm to install and set 1.9.3 active? How do I manage my version of rails?

My attempts to manually install and use rvm for the initial installation failed horribly, for some reason gem would refuse to get anything. For example: gem install rails would produce a "package not found, count <= 0" error, and suggesting the alternate option 'rails'. I wiped my VM image to be sure and am trying again, but I want to do this right.

Paul MaudDib fucked around with this message at 22:54 on Nov 16, 2011

Adbot
ADBOT LOVES YOU

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


You'll want to install RVM first, before rubygems. See if that helps.

In an odd coincidence, lately I've been contributing to a set of instructions for that kind of thing.

If you have any problems with the Ubuntu section (besides it not giving working urls for the rubygems packages for 8.04 and 8.10), please let me know: we're going to walk a ton of people through this on Friday, and I want to get out in front of any mistakes or unclear bits.

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.

Doc Hawkins posted:

You'll want to install RVM first, before rubygems. See if that helps.

In an odd coincidence, lately I've been contributing to a set of instructions for that kind of thing.

If you have any problems with the Ubuntu section (besides it not giving working urls for the rubygems packages for 8.04 and 8.10), please let me know: we're going to walk a ton of people through this on Friday, and I want to get out in front of any mistakes or unclear bits.

Nice! But you might think about teaching Postgres if you're promoting Heroku.

NotShadowStar
Sep 20, 2000
It doesn't really matter what RDBMS you're using as long as you stick to AR migrations. You can develop locally on sqlite and push to Heroku and Postgre without too much issue.

hepatizon
Oct 27, 2010

NotShadowStar posted:

Ruby forks aren't real OS forked processes, they're handled by the Ruby VM. If you're needing to do that for supporting multiple cores, fire up multiple Ruby processes communicating through DRB or something or use NodeJS. It just added true multithreading.

Yeah could you elaborate on this and Bonzo's comment? I thought they were real processes (although information on multiprocessing in Ruby seems pretty scant), unlike the fake threads in 1.8.7.

soullessshoe
Nov 6, 2011

hepatizon posted:

Yeah could you elaborate on this and Bonzo's comment? I thought they were real processes (although information on multiprocessing in Ruby seems pretty scant), unlike the fake threads in 1.8.7.

Ruby forks are real processes (child of the parent).

I think he might be thinking of ruby threads?

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.

NotShadowStar posted:

It doesn't really matter what RDBMS you're using as long as you stick to AR migrations. You can develop locally on sqlite and push to Heroku and Postgre without too much issue.

I've run into issues where my local sqlite queries ran fine, but imploded when I deployed to Heroku on postgres.

For example, a simple case-insensitive search
Works in SQLite:
code:
  def self.search(search)
    if search
      where('name LIKE ? OR description LIKE ?', "%#{search}%", "%#{search}%")
    else
      scoped
    end
  end
the same for Postgres:
code:
  def self.search(search)
    if search
      where('name ILIKE ? OR description ILIKE ?', "%#{search}%", "%#{search}%")
    else
      scoped
    end
  end
I like SQLite for it's portability (I never write very big apps). I'm open to suggestions as to how to make the same code behave on both databases.

NotShadowStar
Sep 20, 2000
Because you're writing a sql fragment that's database specific. If you want case insensitive downcase everything before it goes into the table instead of relying on the db

Model.where("column LIKE '%?'", params[:butts].downcase)

NotShadowStar fucked around with this message at 22:23 on Nov 17, 2011

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

A MIRACLE posted:

I've run into issues where my local sqlite queries ran fine, but imploded when I deployed to Heroku on postgres.

For example, a simple case-insensitive search
Works in SQLite:
code:
  def self.search(search)
    if search
      where('name LIKE ? OR description LIKE ?', "%#{search}%", "%#{search}%")
    else
      scoped
    end
  end
the same for Postgres:
code:
  def self.search(search)
    if search
      where('name ILIKE ? OR description ILIKE ?', "%#{search}%", "%#{search}%")
    else
      scoped
    end
  end
I like SQLite for it's portability (I never write very big apps). I'm open to suggestions as to how to make the same code behave on both databases.

code:
      where('lower(name) LIKE ? OR lower(description) LIKE ?', "%#{search.downcase}%", "%#{search.downcase}%")

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.

Thanks guys :downs:

Pardot
Jul 25, 2001




For most simple crud apps, sure that's fine. But postgres has a ton of great features that you'll want to eventually take advantage of. Fulltext search that doesn't suck, using more than one index per query (sorry mysql), true serializable snapshot isolation, etc etc etc

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

Pardot posted:

For most simple crud apps, sure that's fine. But postgres has a ton of great features that you'll want to eventually take advantage of. Fulltext search that doesn't suck, using more than one index per query (sorry mysql), true serializable snapshot isolation, etc etc etc
True enough. Postgres rules, and it's cake to set up on Mac these days.

Database lock-in doesn't matter when it's the best and open-source.

8ender
Sep 24, 2003

clown is watching you sleep
Just a quick question about Postgres. In a former (enterprise) life I used to be big into Oracle. I'm now using MySQL with our Rails projects and still a little uncomfortable with the syntax. I've heard that Postgres is similar to Oracle. Is this true? Is it worth checking out?

NotShadowStar
Sep 20, 2000
If SQL is English than MySQL is German. It's... sort of like SQL but it doesn't adhere to any standard.

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

8ender posted:

Just a quick question about Postgres. In a former (enterprise) life I used to be big into Oracle. I'm now using MySQL with our Rails projects and still a little uncomfortable with the syntax. I've heard that Postgres is similar to Oracle. Is this true? Is it worth checking out?

I would skip MySQL just based on how PHP-style bad it is; I've had the UI lie to me about InnoDB tables (which support ACID) when they were MyISAM on disk.

Pardot
Jul 25, 2001




8ender posted:

Just a quick question about Postgres. In a former (enterprise) life I used to be big into Oracle. I'm now using MySQL with our Rails projects and still a little uncomfortable with the syntax. I've heard that Postgres is similar to Oracle. Is this true? Is it worth checking out?

It is more similar than mysql by a long shot, and pl/psql is written to be oracleish, as I understand. I've never used oracle myself, though. Check out http://www.postgresql.org/docs/9.1/static/plpgsql.html

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

Pardot posted:

I've never used oracle myself, though.

Lucky. I remember configuring Rails on my iBook to talk to the CS department's Oracle 8 server back in 2006, and it required downloading about a gigabyte of drivers and other poo poo.

Pardot
Jul 25, 2001




redatcted

Pardot fucked around with this message at 22:16 on Dec 8, 2013

8ender
Sep 24, 2003

clown is watching you sleep
Anyone have experience with mailman (https://github.com/titanous/mailman) ?

I'm looking to build a "dropbox" email address into one of our apps and this looks like it might save me some hassle but I'm at a bit of a loss as to the best way to integrate this. Cron or the Daemons gem? Or am I missing some better way here?

kalleth
Jan 28, 2006

C'mon, just give it a shot
Fun Shoe
holy moly, ruby 1.9.3 and rails 3.1.1 are a pretty amazing combination, speed-wise, compared to even 1.9.2 and 3.0.

I have no proper metrics for this, but the app just feels really responsive, sub~20ms response times for each page request/load, etc.

Got a web application up atm on a 512mb ram vmware VM (single core) used by approx 50-60 people at once, on a single thin balancer, and the load is negligible.

And that's without caching! I'd love to see a 1.9.3 + 3.1.1 comparison vs a php framework, right now.

rugbert
Mar 26, 2003
yea, fuck you
Is anyone still experiencing git push issues with heroku? I keep timing out but the support page says everything is fixed.

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.

rugbert posted:

Is anyone still experiencing git push issues with heroku? I keep timing out but the support page says everything is fixed.

Not having any problems, pushed last night. Are you on Windows?

I would just open a ticket with support, they're usually good about getting back to you.

A MIRACLE fucked around with this message at 17:26 on Nov 22, 2011

rugbert
Mar 26, 2003
yea, fuck you

A MIRACLE posted:

Not having any problems, pushed last night. Are you on Windows?

Linux

bone app the teeth
May 14, 2008

I made an abstracted method on a whim, but was curious if anyone had a way to clean it up. I can't figure out how to generate the proper Arel object that will take a receiver of Arel#or.

code:
def has_search(*fields)
  scope :search, ->(query) do
    q = "%#{query}%"
    sql = _[fields.first].matches(q)
    fields[1..-1].each { |field| sql = sql.or(_[field].matches(q)) }
    where(sql)
  end
end
So on the model I include the concern in, I can call has_search :column, :column. Anyone have ideas?

TheAsterite
Dec 31, 2008

Doc Hawkins posted:

You'll want to install RVM first, before rubygems. See if that helps.

In an odd coincidence, lately I've been contributing to a set of instructions for that kind of thing.

If you have any problems with the Ubuntu section (besides it not giving working urls for the rubygems packages for 8.04 and 8.10), please let me know: we're going to walk a ton of people through this on Friday, and I want to get out in front of any mistakes or unclear bits.

I'm trying to use your tutorial to install rails for a school project, and I'm having an issue where when I try to start the rails server, it can't find the java script runtime, even though I've install the JRE and JDK. Any tips?

Edit: Nope, I'm using Ubuntu in a VM.
vvvvvvvvvvvvvvvvvvvv

Edit2: That didn't work

Edit3: Got it working with execjs and nodejs

TheAsterite fucked around with this message at 04:41 on Nov 28, 2011

Molten Llama
Sep 20, 2006
JavaScript, not Java. Completely different (albeit similarly-named) technologies.

Unless you know you need a specific JS runtime, gem install therubyracer and you should be set. No guarantees that won't be incredibly painful if you're on Windows; I haven't tried it.

Deus Rex
Mar 5, 2005

I'd like to use the Yelp! API with my app to search for businesses near locations associated with models in my DB. The way I envision it is with a SearchController for managing requests, probably with just an index action. I think that the business logic of fetching the search results (connecting to api.yelp.com, authenticating, sending the request, receiving the results) should be handled by a model, but I'm unsure of where to start with this.

I'm fairly sure this Search model should stay the hell out of the database, so it won't be subclassing ActiveRecord. Should I look into subclassing ActiveModel instead? Another issue I might have is that my Rails app will be stuck waiting for the results from Yelp! and won't be able to serve other requests in the meantime, which could really suck.

Is there anything I should be reading about this? :)

NotShadowStar
Sep 20, 2000
Your models don't have to subclass AR, that's just the most common. I've written models that don't subclass anything and they perform File I/O. So you can make a standalone class that handles the business of communicating with Yelp.

Newbsylberry
Dec 29, 2007

I Swim in drag shorts because I have a SMALL PENIS
Sorry for this, but I am copying code from the tutorial guide, and it's giving me all types of errors. I have Rails 3.1.1, and ruby 1.9.2p290.

code:
describe "password validations" do

it "should require a password" do
  User.new @attr_merge(:password => "", :passwordConfirmation => "")).
    should_not be_valid
end

it "should require a matching password confirmation" do
  User.new(@attr_merge(:passwordConfirmation => "invalid")).
    should_not be_valid
end

it "should reject short passwords" do 
  short = "a" * 5
  hash = @attr_merge(:password => short, :passwordConfirmation => short)
  User.new(hash).should_not be_valid
end

it "should reject long passwords" do
  long = "a" * 41
  hash = @attr_merge(:password => long, :passwordConfirmation => long)
  User.new(hash).should_not be_valid
end
end
is giving me these errors:

code:
user_spec.rb:61: syntax error, unexpected '(', expecting keyword_end (SyntaxError)
  User.new @attr_merge(:password => "", :passwordConfirmation => "")).
                       ^
/home/cm_user/Documents/railsProjects/demoProject/spec/models/user_spec.rb:66: syntax error, unexpected '(', expecting ')'
  User.new(@attr_merge(:passwordConfirmation => "invalid")).
                       ^
/home/cm_user/Documents/railsProjects/demoProject/spec/models/user_spec.rb:66: syntax error, unexpected ')', expecting keyword_end
  User.new(@attr_merge(:passwordConfirmation => "invalid")).
                                                          ^
/home/cm_user/Documents/railsProjects/demoProject/spec/models/user_spec.rb:72: syntax error, unexpected '(', expecting keyword_end
  hash = @attr_merge(:password => short, :password...
                     ^
/home/cm_user/Documents/railsProjects/demoProject/spec/models/user_spec.rb:72: syntax error, unexpected tASSOC, expecting tCOLON2 or '[' or '.'
...short, :passwordConfirmation => short)
...                               ^
/home/cm_user/Documents/railsProjects/demoProject/spec/models/user_spec.rb:78: syntax error, unexpected '(', expecting keyword_end
  hash = @attr_merge(:password => long, :passwordConfirmation => long)
                     ^
/home/cm_user/Documents/railsProjects/demoProject/spec/models/user_spec.rb:78: syntax error, unexpected tASSOC, expecting tCOLON2 or '[' or '.'
  hash = @attr_merge(:password => long, :passwordConfirmation => long)
Anyone have any help? I am ready to ditch this book, but it's been more helpful then any other I've had. I am really enjoying myself, but it can get frustrating because I don't have a TON of time to work on RoR in general, and I hate wasting it trying to figure out what the gently caress I'm doing wrong.

Edit - I'm sorry for breaking the tables, not really sure how to fix it. I'm a mess.

Newbsylberry fucked around with this message at 00:13 on Dec 1, 2011

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.

I'm a noob help me.

I want my form select tags to retain their search parameters.

code:
# this works fine
text_field_tag :keyword, params[:keyword], :class => "form_field"

# this doesn't keep the param
select(params[:results_per_page], "results_per_page", ["10", "30", "100"])

# neither does this
select(params[:group_id], "group_id", Group.all.collect { |g| [raw(g.group_name), g.id] }, { :include_blank => true })

NotShadowStar
Sep 20, 2000

Newbsylberry posted:

Sorry for this, but I am copying code from the tutorial guide, and it's giving me all types of errors. I have Rails 3.1.1, and ruby 1.9.2p290.


You have an unmatched parens in the fourth line. Whatever book you have, it's awful.

Newbsylberry
Dec 29, 2007

I Swim in drag shorts because I have a SMALL PENIS
Probably, but I'm awful in this scenario, I just copied it wrong. I actually spotted it right when I hit refresh in TCOC. Unfortunately that didn't solve my problems, really my issue is that I'm an idiot and have @attr_merge, instead of @attr.merge. Also an error on my end, not with the book.

Sorry for wasting your time.

manero
Jan 30, 2006

A MIRACLE posted:

I'm a noob help me.

I want my form select tags to retain their search parameters.

code:
# this works fine
text_field_tag :keyword, params[:keyword], :class => "form_field"

# this doesn't keep the param
select(params[:results_per_page], "results_per_page", ["10", "30", "100"])

# neither does this
select(params[:group_id], "group_id", Group.all.collect { |g| [raw(g.group_name), g.id] }, { :include_blank => true })

The trick here is that any view form helper that ends with "_tag" is *not* for dealing with models. So select(), is for dealing with models (i.e. inside "form_for :bla do |form|"), whereas select_tag is a bit more generic and requires more customization.

Try this:

code:
select_tag "group_id", options_from_collection_for_select(Group.all, :id, :name, params[:group_id]), :include_blank => true
The last argument to options_from_collection_for_select is the "selected" value. You should also set @groups in the controller and get "Group.all.collect" code out of the view, so it could look like:

code:
select_tag "group_id", options_from_collection_for_select(@groups, :id, :name, params[:group_id]), :include_blank => true

manero fucked around with this message at 19:34 on Dec 1, 2011

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.

manero posted:


You're the man! The second example did the trick. I guess I'll learn to use select_tag instead of select in the future.

e: Anyone know how to escape the html `options_from_collection_for_select` produces? I'm getting some &-amp's in my options tags. I tried calling raw, html_safe on it to no avail.

A MIRACLE fucked around with this message at 22:48 on Dec 2, 2011

Newbsylberry
Dec 29, 2007

I Swim in drag shorts because I have a SMALL PENIS
I'm trying to have a website with several sub sites that have similar dynamic features (forums, users, etc.), but have different static pages, links, etc. What's the best way to do this? I'm still a newb, but I want to do the right stuff now to make my life easier in the future. It may be a long answer, so if people want to just point me in the right direction I can google up a storm.

hmm yes
Dec 2, 2000
College Slice
There is a Radiant extension that adds support for multisites, if that's the approach you want to take. It's a few years old now, but the concept is basically the same: associate all content models with a site model, and load the correct site on each request based on the request.host. request.host may have been replaced in Rails 3, I don't remember for sure.

Source code: https://github.com/radiant/radiant-multi-site-extension

Railscasts has a subdomain example, which you could also modify for your needs:

http://asciicasts.com/episodes/221-subdomains-in-rails-3

CanCan's ability.rb allows you to restrict access to objects based on attributes. So you could easily do something like:

code:
if user.present?
  can :manage, Post, :user_id => user.id
end
And then you can slide in site_ids for administrative stuff, if you ever need it.

hmm yes fucked around with this message at 05:11 on Dec 5, 2011

enki42
Jun 11, 2001
#ATMLIVESMATTER

Put this Nazi-lover on ignore immediately!
My company does a bunch of stuff like what you're describing, Newbsylberry, and we built a gem for dealing with some of it - https://github.com/bradrobertson/apartment

Basically, the idea with it is that this gem will switch over to different databases (or schemas if you're using postgres on heroku) depending on something like the subdomain of the request coming in (or really whatever you want). We like it a lot better than the scoping thing everyone tends to do since you don't need to add columns like site_id to every table in your app, and once you have things set up, you don't need to think about it (other than running a different version of db:migrate)

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug
Unless the sites are going to share users, I'd just put each one in a separate Heroku instance and maybe write a rake task that git pushes to each one to deploy. That way you don't have to worry about columns or schemata at all.

enki42
Jun 11, 2001
#ATMLIVESMATTER

Put this Nazi-lover on ignore immediately!

BonzoESC posted:

Unless the sites are going to share users, I'd just put each one in a separate Heroku instance and maybe write a rake task that git pushes to each one to deploy. That way you don't have to worry about columns or schemata at all.

Yeah, actually I tend to skip by this approach and it's effective as long as you're not sharing data or have a large number of sites (large being anything more than 5 or so in my experience). We actually used this approach at my company until the number of clients became infeasible to manage separately.

Adbot
ADBOT LOVES YOU

Newbsylberry
Dec 29, 2007

I Swim in drag shorts because I have a SMALL PENIS

enki42 posted:

Yeah, actually I tend to skip by this approach and it's effective as long as you're not sharing data or have a large number of sites (large being anything more than 5 or so in my experience). We actually used this approach at my company until the number of clients became infeasible to manage separately.

How hard was it to switch after that? I'm trying to figure out what will best serve my current need, and not limit me in the future. Right now I just need that division to demonstrate that it's possible, so what Bonzo suggested would be perfect. In the future though, I want to have the users of the subsites also be able to interact at a higher level. So if the subsites are neighborhoods, in the future it would be nice to have them interact within their city as well as their neighborhood, and so on.

If anyone has reading I can look over so I don't feel so overwhelmed that would be sweet.

I really appreciate your patience, let me know if there is a better place to ask my newb questions. Or if I should just start a new thread to contain all my issues.

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