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
8ender
Sep 24, 2003

clown is watching you sleep
I've been using Speedyrails, which is a managed VPS based service. Its actually pretty nice to have a managed VPS because you have all the freedom of root access with a safety net in place in case you really gently caress things up. They also handle regular patching and updates and provide you with a great Capistrano recipe to start which is nice

Adbot
ADBOT LOVES YOU

bitprophet
Jul 22, 2004
Taco Defender
If you just want to learn how to write Rails apps (and are fine with staying with the exact components they offer) Heroku is, as mentioned, your best bet. If you want to learn how to administer a Rails-capable Web server (or want to work with a different set of tools) then you probably don't want to use Heroku because they abstract everything away for you.

Basically, development vs operations/systems administration. If you definitely want to learn the systems side of Web dev, read on!

Rackspace Cloud is probably the best combo of quality/price for virtual servers. You're charged pennies on the hour, which means if you spin up a new instance to play with Technology X and then decide to nuke it a day later, you've lost less than a dollar (and they often don't even bother charging for short-lived instances, in my experience.) And you can create/delete/update instances on the fly via a control panel.

Amazon Web Services (EC2, S3 etc etc) is another, similar (and older, and more "enterprisey") setup, but it's a bit more work to cobble together a simple working server, and more expensive, at least on the low end. On the other hand, AWS experience is useful to have, career-wise.

If you want a more "classic" VPS setup (heh...now I feel old. VPS as classic?) which gives you more "static" instances that are charged monthly, Linode or RimuHosting are excellent providers.

Linode may also have a cloud-style control panel, though I think it's limited to reimaging a handful of specific instances -- i.e. you pay monthly for X amount of RAM/HDD space and might have to go through billing to spin up more servers. I'm sure some of the other posters can clarify this.

BrokenDynasty
Dec 25, 2003

bitprophet posted:

If you just want to learn how to write Rails apps (and are fine with staying with the exact components they offer) Heroku is, as mentioned, your best bet. If you want to learn how to administer a Rails-capable Web server (or want to work with a different set of tools) then you probably don't want to use Heroku because they abstract everything away for you.

Basically, development vs operations/systems administration. If you definitely want to learn the systems side of Web dev, read on!

Is there a middle ground? Is there somewhere for those of us who have rolled a few of our own apps, and dont' want to deal with some of the limitations that Heroku imposes, but aren't yet comfortable being system administrators? I am trying to learn and extend my experience with rails to the point that I find Heroku limiting, but don't want to divide my focus to learn the sysadmin side of things.

If I went with linode or rimu I have to pick a distribution, and then update Ruby to the version I am using locally (on OSX) and then proceed to install/update Rails to whatever version I want and gem and git. Do most of things come standard on a certain *nix distro that is offered by those providers?

When I gently caress things up, can I just flatten what I've done and start again? I guess I'd like a situation where I started similar to when I did on OSX. I had Ruby already baked in and rails as well, I just had to do some updating of a few things and I hate the latest and greatest and was able to go from there, but I'm not sure if my experience with Linode would be far more difficult than that.

8ender
Sep 24, 2003

clown is watching you sleep

BrokenDynasty posted:

Is there a middle ground? Is there somewhere for those of us who have rolled a few of our own apps, and dont' want to deal with some of the limitations that Heroku imposes, but aren't yet comfortable being system administrators? I am trying to learn and extend my experience with rails to the point that I find Heroku limiting, but don't want to divide my focus to learn the sysadmin side of things.

The one I mentioned earlier, Speedyrails, is exactly this. They handle the day to day systems administration but you still have SSH admin access to get in there and mess around. Each VPS comes setup for one app with a mysql database, SMTP, and whatever gems you want them to pre-install. They give you a nice Capistrano recipe to deploy with as well. Your choice of Apache + Passenger (recommended) or Mongrel.

Its full service so at any point you can email them to install or configure something for you. I emailed them from a junkyard the other day to install an SSL certificate and it was done with Apache restarted inside of 10 minutes. If you work at a company with a small development team its a huge boon to not have to hire sysadmins or babysit servers.

8ender fucked around with this message at 15:13 on Sep 1, 2010

UxP
Aug 27, 2007

Nolgthorn posted:

I believe the current rails 3 auth favourite is devise. http://github.com/plataformatec/devise

I have yet to start any rails 3 apps, but am building a timetable to get some of my 2.3.5 apps over to 3 before the end of the year. Besides the obvious devise blog and railscasts for information, does anyone know of an awesome blog post or tutorial on migrating from Authlogic to Devise?

canned from the band
Sep 13, 2007

I'm a man of intensity. Of cool, and youth, and passionately

UxP posted:

I have yet to start any rails 3 apps, but am building a timetable to get some of my 2.3.5 apps over to 3 before the end of the year. Besides the obvious devise blog and railscasts for information, does anyone know of an awesome blog post or tutorial on migrating from Authlogic to Devise?

The README on the github page says:

"Devise implements encryption strategies for Clearance, Authlogic and Restful-Authentication."

Authlogic is really nice but the main benefit of devise is that it seems pretty customisable.

Master_Odin
Apr 15, 2010

My spear never misses its mark...

ladies
Hopefully can someone help a Rails newb here.

My boss wanted me to learn Ruby on Rails for some of his various sites that were written in it. While I'm not having a too too hard pickup up the basics, his first demand was that I make it so you could access a beta site on the same server. The server is setup as:
/
--ruby/
-----beta/
-----gfw/

it uses the gfw directory by default to view the site since that's what was installed first I guess (again, I'm rather new to rails so I'm not completely sure either). Obviously sticking beta as a subdirectory doesn't work (unless there's a way to allow it to go to subdomains instead of serving up a 404 error.

So how could I make http://www.websitedomain.com/beta go to the beta directory instead of giving me a drat 404 error is the question.

Pardot
Jul 25, 2001




Master_Odin posted:

So how could I make http://www.websitedomain.com/beta go to the beta directory instead of giving me a drat 404 error is the question.

If you're talking separate rails apps, you're going to need to have port 80 on websitedomain.com be served by nginx or apache (or whatever), then proxy /beta and /gfw to the correct apps.

The easy way to go here is passenger and I recommend nginx over apache, but it doesn't really matter.

edit: and just for a pitty story, tomorrow is going to be a day in the debugger for me :smith: Updated our app to rails 3 and now authlogic works great in development and test and celerity environments, but doesn't work in qa or production environments :argh:

cultureulterior
Jan 27, 2004
I'm using jruby with jetty (without rails or rack or anything) and I keep hearing conflicting things about how threading works. Does anyone have a link to somewhere with a good summary about what you can and can't do with jruby in a threaded concurrent environment?

In particular, what about transporting ruby or java objects between threads?

cultureulterior fucked around with this message at 16:30 on Sep 9, 2010

this one guy
Mar 15, 2006

Beneath Apple ProDOS
FOR USERS OF APPLE II PLUS, APPLE IIe AND APPLE IIc COMPUTERS
I've got a quick question that I can't seem to find the answer to via Google or irc...

I'm running Rails 3.0.0 and I've got a class in the lib directory which is required from environment.rb. I'm trying to use the Rails logger (i.e. Rails.logger.info "foo") inside that class, but when I try to start the console or the server, I get
code:
lib/my_class.rb:4:in `<class:MyClass>': undefined method `info' for nil:NilClass (NoMethodError)
Anyone run into this? I can't think of any reason why the general Rails logger would be inaccessible from a library class...

Master_Odin
Apr 15, 2010

My spear never misses its mark...

ladies
Apparently I can't even make something as simple as a mail form.

So I've got two files for it contact_controller.rb, notifier.rb.

Contact controller is a simple:
code:
class ContactController < ApplicationController
	def index
		# get index.html.erb
	end
	
	def create
		
		redirect_to(:controller => 'admin')
	end
end
so when I go to /contact, it loads the index.html.erb file and I see my form and everything. However, when I submit the form, I get a 500 error.

My routes for it:
code:
  map.with_options :controller => 'contact' do |contact|
  contact.contact '/contact',
    :action => 'index',
    :conditions => { :method => :get }

  contact.contact '/contact',
    :action => 'create',
    :conditions => { :method => :post }
  end
My form is:
code:
<form action="/contact" method="post">
any help on the issue since it has to be something obvious I'm sure would be appreciated!

NotShadowStar
Sep 20, 2000

Ace McLamesauce posted:

I've got a quick question that I can't seem to find the answer to via Google or irc...

I'm running Rails 3.0.0 and I've got a class in the lib directory which is required from environment.rb. I'm trying to use the Rails logger (i.e. Rails.logger.info "foo") inside that class, but when I try to start the console or the server, I get
code:
lib/my_class.rb:4:in `<class:MyClass>': undefined method `info' for nil:NilClass (NoMethodError)
Anyone run into this? I can't think of any reason why the general Rails logger would be inaccessible from a library class...

Can you move it to vendor/plugins instead of lib? Using lib has been discouraged since like... 1.0 and probably has a different load order.

canned from the band
Sep 13, 2007

I'm a man of intensity. Of cool, and youth, and passionately

Master_Odin posted:


My routes for it:
code:
  map.with_options :controller => 'contact' do |contact|
  contact.contact '/contact',
    :action => 'index',
    :conditions => { :method => :get }

  contact.contact '/contact',
    :action => 'create',
    :conditions => { :method => :post }
  end

No one really writes routes that specific. Rails makes it easy if you use the RESTful conventions. You could get all the routes you need by writing:

code:
map.resources :contacts
Checkout the Rails Guides (this is for the last version of Rails 2.3.8) for a good introduction to routes.

8ender
Sep 24, 2003

clown is watching you sleep

B1axident posted:

No one really writes routes that specific. Rails makes it easy if you use the RESTful conventions. You could get all the routes you need by writing:

I just want to say that this sort of thing has been the hardest for me coming from a Java background to Ruby. I'm trained to default to the most complex solution and I have built up a huge tolerance for bullshit so I often never even consider that things could or should be easier.

Just the other day I recreated most of the x.sum(:thing) function in some of my code before I checked the docs :(

8ender fucked around with this message at 07:42 on Sep 11, 2010

skidooer
Aug 6, 2001

Master_Odin posted:

any help on the issue since it has to be something obvious I'm sure would be appreciated!
Add the following to your controller:

code:
skip_before_filter :verify_authenticity_token
Or, even better, use the form builders so that the token is added automatically.

drjrock_obgyn
Oct 11, 2003

once i started putting pebbles in her vagina, there was no going back
To everyone asking about servers and managed hosting, I highly recommend moonshine: http://github.com/railsmachine/moonshine for managing your own servers. It's really easy to install and configure everything and if you're using a vps you can always roll back pretty easily.

NotShadowStar
Sep 20, 2000
So, that Diaspora project about making an OSS, decentralized Facebook replacement went public for developer contributions today. It's written in Rails 3. The base code is pretty nice to work with so far. They need lots of help. Go for it!

http://github.com/diaspora/diaspora

e: christ, one of the dependencies doesn't work on 1.9.2 ffffffff

ee: nevermind, this is a huge loving trainwreck and it'll probably fail. This is very obviously '4 kids with some basic knowledge and 200,000 dollars try to do something cool'. There is no design documentation, no direction, the internals are a loving mess and nobody has any idea what to do with it because these 4 kids don't know what the gently caress they're doing with it.

NotShadowStar fucked around with this message at 02:05 on Sep 17, 2010

8ender
Sep 24, 2003

clown is watching you sleep

NotShadowStar posted:

ee: nevermind, this is a huge loving trainwreck and it'll probably fail. This is very obviously '4 kids with some basic knowledge and 200,000 dollars try to do something cool'. There is no design documentation, no direction, the internals are a loving mess and nobody has any idea what to do with it because these 4 kids don't know what the gently caress they're doing with it.

I had sort of written off the whole thing as an architecture astronaut adventure when I first heard about it. Let's tally up the three main warning signs:

- Going way out of their way to make it "distributed" and "decentralized"
- Development team is 4 mathematicians working from academia
- Backing from a crazy technology magnate who will personally derail the project constantly

Okay so the third, backing from Ray Ozzie, hasn't happened yet. You can be assured that he knows about this though and is probably flying a helicopter to New York right now.

hmm yes
Dec 2, 2000
College Slice
I'm going to have read-only access to a remote Oracle database, and I need to pull some of the tables from it into a different database on a regular basis. Anyone know of an existing gem that will let me do this? taps was my first thought, but it looks like I need to have the taps gem installed and running on the remote server in order to make the connection, and that's not going to be possible. Many other export/import scripts I have found are MySQL specific.

hmm yes fucked around with this message at 18:26 on Sep 18, 2010

BrokenDynasty
Dec 25, 2003

atastypie posted:

I'm going to have read-only access to a remote Oracle database, and I need to pull some of the tables from it into a different database on a regular basis. Anyone know of an existing gem that will let me do this? taps was my first thought, but it looks like I need to have the taps gem installed and running on the remote server in order to make the connection, and that's not going to be possible. Many other export/import scripts I have found are MySQL specific.

Is writing a migration out of the question?

Randuin
Dec 26, 2003

O-Overdrive~

NotShadowStar posted:

So, that Diaspora project about making an OSS, decentralized Facebook replacement went public for developer contributions today. It's written in Rails 3. The base code is pretty nice to work with so far. They need lots of help. Go for it!

http://github.com/diaspora/diaspora

e: christ, one of the dependencies doesn't work on 1.9.2 ffffffff

ee: nevermind, this is a huge loving trainwreck and it'll probably fail. This is very obviously '4 kids with some basic knowledge and 200,000 dollars try to do something cool'. There is no design documentation, no direction, the internals are a loving mess and nobody has any idea what to do with it because these 4 kids don't know what the gently caress they're doing with it.

Just leave it to google

hmm yes
Dec 2, 2000
College Slice

BrokenDynasty posted:

Is writing a migration out of the question?

No, I could write a migration. I can have access the database with a rails app if it's purpose is to export/sync the data.

rugbert
Mar 26, 2003
yea, fuck you
Whats the best way to install Ruby Gems and then Rails on an ubuntu server? My boss is telling me to install gems from source because apt-get fucks it up and is out of date so gems cant update it self or install new gems. Confirm/Deny

Obsurveyor
Jan 10, 2003

rugbert posted:

Whats the best way to install Ruby Gems and then Rails on an ubuntu server? My boss is telling me to install gems from source because apt-get fucks it up and is out of date so gems cant update it self or install new gems. Confirm/Deny
Use rvm. Ubuntu's package management for ruby sucks balls.

bitprophet
Jul 22, 2004
Taco Defender

Obsurveyor posted:

Use rvm. Ubuntu's package management for ruby sucks balls.

This. The default Debian/Ubuntu Ruby interpreter itself tends to work fine, it's the gems that has the big bruhaha surrounding it, so I typically aptitude install ruby1.8 ruby1.8-dev ri irb etc etc but don't include rubygems here and then install rubygems from source (grab tgz, unpack, ruby setup.rb install).

RVM has a bunch of neat features like gemsets, though, and makes it stupid easy to manage different Ruby versions. So if your server is going to host multiple apps, especially ones that might need different Ruby versions among them, it's totally the way to go.

dustgun
Jun 20, 2004

And then the doorbell would ring and the next santa would come
I swear that sometime in the last month I read something about a new rails 3 engine or app that acted like django-admin. Any help?

edit: hurrr http://github.com/sferik/rails_admin

dustgun fucked around with this message at 20:16 on Sep 26, 2010

SamMalone
Aug 3, 2006
I'm always smoking!
I have what is I'm sure an absurdly newbie question to ask, but I just started learning RoR for work, and I've been trying to work in a feature where a user can enter Time and Date in two form text fields, and they get combined into a datetime to be stored in the database. Everything works fine if they're correct, but I'm having trouble with the error handling. I use the Time.parse method, which is supposed to throw an ArgumentError if you pass it in something it can't make a time value out of, but when I throw it nonsense, it seems to just default to the current day instead of throwing an error.

With the following code,

code:
def my_date=(date)
	puts "Time.parse(" + date + ") ="
        puts Time.parse(date).to_s

        #other code elided

  	rescue ArgumentError
  	errors.add(:my_date, 'is an invalid date or is formatted incorrectly.') 
  end
I get the following message in the server when I enter date = NOT A DATE:

code:
Time.parse(NOT A DATE) = 
Wed Oct 06 09:52:37 -0400 2010
So... shouldn't it be throwing an ArgumentError? I'm not sure if my syntax is even correct for catching the error, but it doesn't even seem to throw one - it just goes right to the current date. I'm using rails 2.3.5 and ruby 1.8.7. I'm very new to this stuff, so it could very well be something obvious. Is it possible there's some gem or plugin that is affecting the parse method's behavior? Please, anybody who could help, I'd really appreciate it.

Flobbster
Feb 17, 2005

"Cadet Kirk, after the way you cheated on the Kobayashi Maru test I oughta punch you in tha face!"
I'm only a casual Ruby user, but I think you have to surround the code you want to trap errors from in a begin/rescue/end block:

code:
def my_date=(date)
  begin
    puts "Time.parse(" + date + ") ="
    puts Time.parse(date).to_s

    #other code elided

  rescue ArgumentError
    errors.add(:my_date, 'is an invalid date or is formatted incorrectly.')
  end
end

SamMalone
Aug 3, 2006
I'm always smoking!

Flobbster posted:

I'm only a casual Ruby user, but I think you have to surround the code you want to trap errors from in a begin/rescue/end block:

Thanks for the help. Unfortunately, I've tried that and it doesn't seem to make a difference. I'm pretty sure that if you have a rescue statement at the end of the method it by default rescues all the code in the method. Anyway, if the rescue block wasn't working, it should still throw an error and just make the application break, which it isn't doing.

I put in another puts statement inside the rescue block just to check if an error even got thrown and was just handled inappropriately, and the error doesn't even get thrown. I don't understand why Time.parse isn't throwing an error when I ask it to parse 'NOT A DATE'. Anybody have any ideas or experience with a similar error?

Flobbster
Feb 17, 2005

"Cadet Kirk, after the way you cheated on the Kobayashi Maru test I oughta punch you in tha face!"

SamMalone posted:

Thanks for the help. Unfortunately, I've tried that and it doesn't seem to make a difference. I'm pretty sure that if you have a rescue statement at the end of the method it by default rescues all the code in the method.

Ah, it does appear that's the behavior. Cool, I learned something new!

I'm seeing the same behavior that you are on Ruby 1.8.7 on Mac OS X 10.6. According to one poster here, it looks like the raising ArgumentError behavior wasn't added until 1.9.2, unfortunately.

NotShadowStar
Sep 20, 2000
1) When dealing with data in models, don't use exceptions, use validators.
2) There is a DateTime class that you should probably use instead of making a Date and a Time and then combining them if you are, in fact, storing a date and time in a database field.
3) Somebody already did this for you http://github.com/adzap/validates_timeliness/

SamMalone
Aug 3, 2006
I'm always smoking!
blah, that's no good. Unfortunately I'm not supposed to update my version just yet.

Anyway, apparently there's a work around if anyone's in a similar situation. For some reason, Time.zone.parse() will return nil if its unable to parse, i.e. it actually checks correctly. So in Ruby 1.8.6, you can check for errors with something like this

code:
Time.zone = 'Hawaii' #or whatever time zone you like, it's only for error testing, 
                     #but we can't leave it uninstantiated
if Time.zone.parse(my_date).nil?
  #handle errors here
end
edit: ^^^^^^^thanks, that makes sense, and the hack-y-ness of the solution in this post was kind of hinting to me that I was doing something stupid organization-wise.

SamMalone fucked around with this message at 16:52 on Oct 6, 2010

rugbert
Mar 26, 2003
yea, fuck you
Anyone have a good tutorial for how routing works? Super noob right here and my boss is too boring to listen too.

Pardot
Jul 25, 2001




rugbert posted:

Anyone have a good tutorial for how routing works? Super noob right here and my boss is too boring to listen too.

http://guides.rubyonrails.org/routing.html

All of http://guides.rubyonrails.org is great.

rugbert
Mar 26, 2003
yea, fuck you

Thanks!

Flamadiddle
May 9, 2004

So I have a not-very Googleable question about Rails' capabilities. I've not built a full site yet, but I'm hoping to build a new development on Rails.

I have some SQL Server tables like so:

code:
Table 1:
Column  Datatype 
------  -------- 
myDate   date    
myName   String
...


Table 2:

Column   Value(varchar)
------   ------
myDate   2010-01-01
myName   John
...
What I'm hoping to do is to create a form in Rails to populate entries in table 2 which will dynamically validate the contents of a "Value" field dependent on the datatype specified in the row. I'm hoping that this is relatively straightforward. Obviously I could filter any GET/POST data after the fact, but ideally the field would be preset as the necessary data already exists in table 1. I just really like the way Ruby does client/server-side validation by itself.

Any insight as to whether this is even possible in Rails (ideally more-so than post-submission) would be appreciated.

NotShadowStar
Sep 20, 2000
You're thinking about it like PHP. Never do validation in controllers or views, let the model do the work.

It sounds like you want an association though, which are mostly automatic if done right. Can you be more specific on the data? We could help you much better on the design.

Flamadiddle
May 9, 2004

NotShadowStar posted:

You're thinking about it like PHP. Never do validation in controllers or views, let the model do the work.

It sounds like you want an association though, which are mostly automatic if done right. Can you be more specific on the data? We could help you much better on the design.

Sure. What I have are a number of tables in various databases that contain non-presentable data (some data has to be shortened to make it fit the system tables, but we want to present it on the web or various documents. Rather than duplicate the data, we're building a system that generates SQL views based on the original, dirty, table coupled with this "override" table. This will be the presentable face of the underlying tables, with all the rough data tidied over.

All the Ruby app will be for is providing a front-end for adding and editing these overrides. I just want to be sure that when you add an override for, for example, a person's name, the result is validated as a varchar, and when you provide an integer for an age, it's validated as an integer, even though both the name and the integer are held as varchar values in the "override" table.

I've been working with PHP a lot recently and feel stupid for not thinking about this as the work of the model.

I was hoping to just slap Rails onto the existing table structures and then do some work on the validation side so it doesn't just naively validate everything as a string. All the relationships are sound. I'm just not sure how to tell Rails that the validation rules on a certain field are based on the value of a related field.

Is this enough info to get across what I'm trying to do?

NotShadowStar
Sep 20, 2000

Flamadiddle posted:

I was hoping to just slap Rails onto the existing table structures


This is pain. You can do it, but it's full of pain especially if you are very new to ActiveRecord. ActiveRecord works best if you follow its conventions. AR is full of 'convention over configuration' and that includes table and column names for automatic class, property and association matching. You can override all of these but it becomes more confusing if you're not already familiar with AR.

What I would suggest you do is not deal with the existing table structure at first and create a whole new scratch Rails app with the perfect data model you have in mind for your existing structure and follow the Rails/AR conventions. Forget about the 'dirty' table and associations and just take what the best way of modeling the data is and build up a new Rails app from scratch.

If you can give a few examples on how you want this to look disregarding all the complicated mess we can help you model your example application.

Or, alternately, do the example project in this book. You'll understand Rails a lot better.

Actually if you have Python experience Django might serve you better, it's model structure doesn't depend so much on the automatic associations as you define everything.

NotShadowStar fucked around with this message at 23:02 on Oct 13, 2010

Adbot
ADBOT LOVES YOU

Flamadiddle
May 9, 2004

Thanks for the advice. Yeah, I'm sure the way we've built our demo system isn't particularly suited for ActiveRecord and we're looking at reworking it.

In an object-oriented way, I'd imagine the solution would involve having an abstract override class, with concrete child classes for each datatype. In Rails, would I then be able to say that a Column object has many Override members, but that these may be of different types as defined by the specific subclass, and have the model validate against these?

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