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
raej
Sep 25, 2003

"Being drunk is the worst feeling of all. Except for all those other feelings."
If I were building a webapp to keep track of artists and albums, and wanted to make a page for users to be able to keep track of what albums that have (and things like condition of album, and if it's vinyl, cd, etc) would Ruby be a place to start?

Basically a database of artists, a database of albums that correspond to artists, and a collection page listing a user's actual albums held.

Adbot
ADBOT LOVES YOU

Cock Democracy
Jan 1, 2003

Now that is the finest piece of chilean sea bass I have ever smelled

raej posted:

If I were building a webapp to keep track of artists and albums, and wanted to make a page for users to be able to keep track of what albums that have (and things like condition of album, and if it's vinyl, cd, etc) would Ruby be a place to start?

Basically a database of artists, a database of albums that correspond to artists, and a collection page listing a user's actual albums held.
You're going to want to use Ruby on Rails, not just Ruby itself. Most people recommend learning Ruby first before diving into Rails, but I didn't go this route and learned them both at the same time. If you have any familiarity with other kinds of programming and web development going into it, I think that helps a lot. Good luck!

raej
Sep 25, 2003

"Being drunk is the worst feeling of all. Except for all those other feelings."

Cock Democracy posted:

You're going to want to use Ruby on Rails, not just Ruby itself. Most people recommend learning Ruby first before diving into Rails, but I didn't go this route and learned them both at the same time. If you have any familiarity with other kinds of programming and web development going into it, I think that helps a lot. Good luck!

I guess I need to learn the lingo as well. I thought I could use Ruby and it was known it was Ruby/Rails.

I checked out Hobo as well, and watching their screencast was inspiring. I have a few years of web development under my belt with fixing client sites and jamming poo poo together to make wordpress sites, but it looks like this is an entirely different beast.

Pardot
Jul 25, 2001




Lexicon posted:

I'm building a rails app which will be hosted on Heroku and pulls data from an RDS MySql connection. Note that this connection is in addition to the Postgres connection to the database that's the persistence layer for the rails app itself.

I've been able to authorize Heroku to connect to the RDS instance; however, it replaces CONFIG['DATABASE_URL'] with the mysql connection string, which is not a huge problem in itself.

The thing is, the value stored there is a Mysql2 connection string: e.g. mysql2://user:pass@....

I want to use the mysql2 gem to connect to this database, and Mysql2::Client.new takes a hash of parameters. Short of doing a regex to pull out these parameters into a hash, is there a way to connect using a connection string?

You can use the URI stdlib

Ruby code:
require 'uri'
URI.parse('mysql2://user:pass@hostname.com/dbname').tap {|a| p [a.scheme, a.user, a.password, a.host, a.path[1..-1]] }
["mysql2", "user", "pass", "hostname.com", "dbname"]

Lexicon
Jul 29, 2003

I had a beer with Stephen Harper once and now I like him.

Pardot posted:

You can use the URI stdlib

Ruby code:
require 'uri'
URI.parse('mysql2://user:pass@hostname.com/dbname').tap {|a| p [a.scheme, a.user, a.password, a.host, a.path[1..-1]] }
["mysql2", "user", "pass", "hostname.com", "dbname"]

Worked perfectly. Thanks!

Smol
Jun 1, 2011

Stat rosa pristina nomine, nomina nuda tenemus.
Just noticed that the mysql gem returns everything as strings (or nil). Why do I have to deal with this kind of crap. :(

Wish I could use PostgreSQL at our shop

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.

Smol posted:

Just noticed that the mysql gem returns everything as strings (or nil). Why do I have to deal with this kind of crap. :(

Wish I could use PostgreSQL at our shop

If you have a choice you could try using the Sequel gem that's been posted about in this thread like 20 times. It gives you a little ORM to work with if that's your thing.

Smol
Jun 1, 2011

Stat rosa pristina nomine, nomina nuda tenemus.
It's a Rails 2.3 app so we're using ActiveRecord where possible. In this case though, the queries I'm building are quite complex and the older versions of ActiveRecord aren't really up to the task (the Arel versions should be fine). ActiveRecord is pretty slow as well, and I really don't want the overhead of ActiveRecord here (we're pulling a quite lot of data from the database and I've measured ActiveRecord to have up to 20x overhead compared to plain Ruby Hashes in the past).

I could replace mysql with mysql2, but the test coverage in this project is not really satisfactory, so I'm pretty hesitant to make large changes like that.

Anyhow, I guess the real story is that good test suite is invaluable.

Smol fucked around with this message at 22:47 on Nov 8, 2012

jony neuemonic
Nov 13, 2009

Sorry if this has been asked before but I didn't catch it while skimming the thread:

Is there a decent ERB reference or cheat sheet out there? Google is coming up dry. I've been playing with Sinatra and DataMapper and find I'm stumbling a little bit on making forms that interact with my Ruby code.

Obsurveyor
Jan 10, 2003

fidel sarcastro posted:

Is there a decent ERB reference or cheat sheet out there? Google is coming up dry. I've been playing with Sinatra and DataMapper and find I'm stumbling a little bit on making forms that interact with my Ruby code.

ERB is pretty simple(and gets out of your way without being obtuse like HAML) but this is probably the best:

http://ruby-doc.org/stdlib-1.9.3/libdoc/erb/rdoc/ERB.html

jony neuemonic
Nov 13, 2009

Obsurveyor posted:

ERB is pretty simple(and gets out of your way without being obtuse like HAML) but this is probably the best:

http://ruby-doc.org/stdlib-1.9.3/libdoc/erb/rdoc/ERB.html

Thanks! It never even occurred to me that the Ruby documentation would cover ERB. :doh:

Knyteguy
Jul 6, 2005

YES to love
NO to shirts


Toilet Rascal
Good God installing Ruby/Rails/Phusion Passenger on a Linux cPanel server without taking over the entire virtual host was a nightmare. I feel like RVM complicated things even further.

The good news is I finally got it working http://www.pluswebhost.com/rails/ :getin:

Maybe I'll write up a tutorial for other developers who want to run it all on their own existing server. All the information is out there, but it's definitely not all in one place.

Quick question: How do I change what environment I'm working with? Rails I'm fairly certain started the configuration on production. Thanks!

MrDoDo
Jun 27, 2004

You better remember quick before we haul your sweet ass down to the precinct.

Knyteguy posted:

Good God installing Ruby/Rails/Phusion Passenger on a Linux cPanel server without taking over the entire virtual host was a nightmare. I feel like RVM complicated things even further.

The good news is I finally got it working http://www.pluswebhost.com/rails/ :getin:

Maybe I'll write up a tutorial for other developers who want to run it all on their own existing server. All the information is out there, but it's definitely not all in one place.

Quick question: How do I change what environment I'm working with? Rails I'm fairly certain started the configuration on production. Thanks!

Set the environment variable RAILS_ENV to whatever (development, production, etc)

Knyteguy
Jul 6, 2005

YES to love
NO to shirts


Toilet Rascal

MrDoDo posted:

Set the environment variable RAILS_ENV to whatever (development, production, etc)

Thanks for the help. So would this be correct? rake RAILS_ENV=development ?

Also if anyone could lend a hand... I'm having some problems with a 500 server error. It's when I try to enter some information to the database.

Website with error:
http://www.pluswebhost.com/rails/posts (hit new post, and try to create)

Code:
https://github.com/Noppadet/RailsBasicApp

Git isn't fetching the sqlite3 files that are present on my development server but I'm guessing that's just a driver? Still really new to the ROR stuff.

Thanks :).

E:
Rails logs aren't showing anything out of the ordinary. Could it be chown rights?

Knyteguy fucked around with this message at 00:00 on Nov 13, 2012

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.

Knyteguy posted:

Git isn't fetching the sqlite3 files that are present on my development server but I'm guessing that's just a driver? Still really new to the ROR stuff.

https://github.com/Noppadet/RailsBasicApp/blob/master/.gitignore#L11

You should have different databases for development, testing and production anyway.

MrDoDo
Jun 27, 2004

You better remember quick before we haul your sweet ass down to the precinct.

Knyteguy posted:

Thanks for the help. So would this be correct? rake RAILS_ENV=development ?

Also if anyone could lend a hand... I'm having some problems with a 500 server error. It's when I try to enter some information to the database.

Website with error:
http://www.pluswebhost.com/rails/posts (hit new post, and try to create)

Code:
https://github.com/Noppadet/RailsBasicApp

Git isn't fetching the sqlite3 files that are present on my development server but I'm guessing that's just a driver? Still really new to the ROR stuff.

Thanks :).

E:
Rails logs aren't showing anything out of the ordinary. Could it be chown rights?

You can specify the env on each command run or you can just export RAILS_ENV and every subsequent command will use that same one

Physical
Sep 26, 2007

by T. Finninho
How do I get a list of all the variables available in a view? Things like the local variables and params?

jetviper21
Jan 29, 2005

Physical posted:

How do I get a list of all the variables available in a view? Things like the local variables and params?

You can always do a params.inspect to dump out all the params in your view as for local variables are you referring to helper methods or the instance variables you define in your controller actions?

Soviet
Jul 17, 2003

stick it in me

Knyteguy posted:

Good God installing Ruby/Rails/Phusion Passenger on a Linux cPanel server without taking over the entire virtual host was a nightmare. I feel like RVM complicated things even further.

The good news is I finally got it working http://www.pluswebhost.com/rails/ :getin:

Maybe I'll write up a tutorial for other developers who want to run it all on their own existing server. All the information is out there, but it's definitely not all in one place.

I would actually really, really appreciate it if you did did this.

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


jetviper21 posted:

You can always do a params.inspect to dump out all the params in your view as for local variables are you referring to helper methods or the instance variables you define in your controller actions?

For instance variables, try: http://rubydoc.info/stdlib/core/Object#instance_variables-instance_method

Physical
Sep 26, 2007

by T. Finninho

jetviper21 posted:

You can always do a params.inspect to dump out all the params in your view as for local variables are you referring to helper methods or the instance variables you define in your controller actions?
Instance variables in the controllers, including the ones with no @ symbol and the stuff you can pass in via render "partial", :locals => {} I want to inspect the :locals hash too.

jetviper21
Jan 29, 2005

Physical posted:

Instance variables in the controllers, including the ones with no @ symbol and the stuff you can pass in via render "partial", :locals => {} I want to inspect the :locals hash too.

They should show up if you do a print out a methods.inspect if I am looking at this correctly: https://github.com/rails/rails/blob/0d3d9a150a4ba1084cf28fd26be2a154f4540952/actionpack/lib/action_view/template.rb#L305-307

or if that doesn't work you can always get them from the binder object
code:
1.9.3-p0-perf :010 > foo = 'bar'
 => "bar" 
1.9.3-p0-perf :011 > binding.send(:local_variables).inspect
 => "[:foo, :_]" 

jetviper21 fucked around with this message at 21:15 on Nov 13, 2012

Pardot
Jul 25, 2001




Knyteguy posted:

Good God installing Ruby/Rails/Phusion Passenger on a Linux cPanel server without taking over the entire virtual host was a nightmare.

I am interested in your reasons for going this route.

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.

Does CPanel even support Rails 3?

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

Pardot posted:

I am interested in your reasons for going this route.

Probably a carbon monoxide leak or brain cancer, if I ever touch cpanel again it will be too soon. Rack and Rails have simply moved faster and in different ways than cpanel can keep up with, even without adding the broken jankiness of rvm into the mix.

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

Physical posted:

How do I get a list of all the variables available in a view? Things like the local variables and params?

What are you trying to do with this?

Knyteguy
Jul 6, 2005

YES to love
NO to shirts


Toilet Rascal

A MIRACLE posted:

Does CPanel even support Rails 3?

Officially there is no easy plugin or update to allow Rails 3 to work on a cPanel server, no. This is only because Mongrel still doesn't work with Rails 3 (according to cPanel). There have been some requests to change the environment in cPanel to something better supported, but there hasn't been any visible progress by cPanel yet.

quote:

I am interested in your reasons for going this route.

Path of least resistance I guess. Some people on the cPanel forums mentioned that mod_rails worked so that's what I went with.

quote:

I would actually really, really appreciate it if you did did this.

Alright when I get some time to figure out the 500 error I'm getting on database writing I'll write up a tutorial.

quote:

You can specify the env on each command run or you can just export RAILS_ENV and every subsequent command will use that same one

Thanks managed to make the setting stick now.

E: Got the 500 error fixed, it was simply chown permissions

Knyteguy fucked around with this message at 03:31 on Nov 14, 2012

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.

Knyteguy posted:

Officially there is no easy plugin or update to allow Rails 3 to work on a cPanel server, no. This is only because Mongrel still doesn't work with Rails 3 (according to cPanel). There have been some requests to change the environment in cPanel to something better supported, but there hasn't been any visible progress by cPanel yet.

This is going on like two years now lol. They must not be trying very hard.

MrDoDo
Jun 27, 2004

You better remember quick before we haul your sweet ass down to the precinct.

Knyteguy posted:



Path of least resistance I guess. Some people on the cPanel forums mentioned that mod_rails worked so that's what I went with.



You really should check out Heroku is all you want to do is mess around with Rails

Pardot
Jul 25, 2001




Speaking of, can I get any of you who use heroku to beta test something I've been working on releasing soon? I'd really appreciate the feedback: https://dataclips.heroku.com

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.

Pardot posted:

Speaking of, can I get any of you who use heroku to beta test something I've been working on releasing soon? I'd really appreciate the feedback: https://dataclips.heroku.com

Wow I need to brush up on my pg syntax. Been mired in mysql for too long.

Anyways this is a neat idea. Have you considered unifying the views from postgres.heroku.com/databases/:db_name/dataclips and dataclips.heroku.com?

A MIRACLE fucked around with this message at 16:23 on Nov 14, 2012

Pardot
Jul 25, 2001




A MIRACLE posted:

Wow I need to brush up on my pg syntax. Been mired in mysql for too long.

Anyways this is a neat idea. Have you considered unifying the views from postgres.heroku.com/databases/:db_name/dataclips and dataclips.heroku.com?

Yeah, the ones on postgres.heroku will be migrated over to the new thing once it's released.

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.

Also a small front-end nitpick,

CSS code:
.icon[media=screen] {
  background-image: none;
}
supercedes
CSS code:
.icon {
  background-image: icons.png;
}
and makes the `create data clip` button look all janky

Physical
Sep 26, 2007

by T. Finninho
What does the number returned by the regexp =~ mean?

request.env['HTTP_USER_AGENT'] =~ "Chrome"

returns 69 in a chrome browser. Best I can tell, it's the index of the first occurance? Regexp are confusing as gently caress to me.


Nevermind, I had to read better!

Physical fucked around with this message at 17:35 on Nov 14, 2012

Lexicon
Jul 29, 2003

I had a beer with Stephen Harper once and now I like him.
Has anyone here tried to pull data from the google analytics API from within a rails app? It seems like an utter clusterfuck with a bunch of defunct gems to interface with it, and Google's own ruby library in alpha.

I can't find half decent sample code anywhere on the web :(

Knyteguy
Jul 6, 2005

YES to love
NO to shirts


Toilet Rascal

MrDoDo posted:

You really should check out Heroku is all you want to do is mess around with Rails

I saw Heroku but thought it was only pay-to-use. It's not a big deal though, I got to brush up on a bit on my server administration skills.

The biggest problem I can see with Heroku though, is if you really ever want to go live with an app it could end up costing a lot due to having to pay to upgrade the plugins to premium eventually. It's like an impulsive developer's nightmare.

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


What would keep you from just migrating to something else if you didn't like the price?

kitten smoothie
Dec 29, 2001

Knyteguy posted:

I saw Heroku but thought it was only pay-to-use. It's not a big deal though, I got to brush up on a bit on my server administration skills.

The biggest problem I can see with Heroku though, is if you really ever want to go live with an app it could end up costing a lot due to having to pay to upgrade the plugins to premium eventually. It's like an impulsive developer's nightmare.

I think the question is what's the value of your time early on in a project. Do you want to spend time computer janitoring a server, or do you want to spend that time writing code that could make you money and deal with migration if it takes off?

Obsurveyor
Jan 10, 2003

kitten smoothie posted:

I think the question is what's the value of your time early on in a project. Do you want to spend time computer janitoring a server, or do you want to spend that time writing code that could make you money and deal with migration if it takes off?

In my personal(work and cloud stuff is a whole different can of worms) situation with just a Windows machine, you need a Unix or Mac environment to develop with Ruby effectively. Setting up a VM or real machine is going to be necessary anyway. Going one more step of setting up apache+passenger or nginx isn't a huge leap from there.

Heroku looks really awesome but until I actually need to deploy something to the Internet for real, it seems to me it would take more time to learn and manage that than just to go with what I know.

Adbot
ADBOT LOVES YOU

Lexicon
Jul 29, 2003

I had a beer with Stephen Harper once and now I like him.

kitten smoothie posted:

Do you want to spend time computer janitoring a server, or do you want to spend that time writing code that could make you money and deal with migration if it takes off?

Seriously, this.

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