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
NotShadowStar
Sep 20, 2000
Leaving in one minute but I don't know if that will even work, since you got to method_missing through a render with a missing template (explicit or implicit) so you'll get a double render error when you get that far. I think. You probably want to look at rescue_action_in_public

Adbot
ADBOT LOVES YOU

Lamont Cranston
Sep 1, 2006

how do i shot foam

NotShadowStar posted:

Leaving in one minute but I don't know if that will even work, since you got to method_missing through a render with a missing template (explicit or implicit) so you'll get a double render error when you get that far. I think. You probably want to look at rescue_action_in_public

Cool. I just changed the code to
code:
  def method_missing(methodname, *args)
    rescue
      render 'error/index', :status => 404
  end
to see if it would work and it does. I'll look into this though, so I'm not messing with method_missing voodoo if I don't have to be.

NotShadowStar
Sep 20, 2000
Okay, even better, Rails now has a rescue_from construction. Provide rescue_from with an exception class and you can invoke a method to handle that. Don't raise exceptions in the other methods though or you could be caught in a loop. These are the end of the chain.

Also remember that 404s and 500s are handled differently in production and development environments. Remember to switch your env to production to test and make sure it works the same.

code:
class ApplicationController<ActionController::Base
  rescue_from ActionView::MissingTemplate, :with => :missing_template
  
  private

  def missing_template(exception)
    render :text => 'You forgot your template dumbass', :status => 404
  end
  
end

Operation Atlas
Dec 17, 2003

Bliss Can Be Bought

Lamont Cranston posted:

I'm trying to implement custom 404 pages using method_missing in my ApplicationController. This code:
code:
  def method_missing(methodname, *args)
    begin
      super
    rescue ActionView::MissingTemplate
      render 'error/index', :status => 404
    end
  end
should do the trick but it throws "ArgumentError (no id given)" when it calls super. I know this can happen if I modify the value of "methodname" but I don't. Any ideas?

Why not just:

code:
def method_missing(*args)
That should fix it. Do you need methodname in particular?

manero
Jan 30, 2006

Lamont Cranston posted:

I'm trying to implement custom 404 pages using method_missing in my ApplicationController. This code:
code:
  def method_missing(methodname, *args)
    begin
      super
    rescue ActionView::MissingTemplate
      render 'error/index', :status => 404
    end
  end
should do the trick but it throws "ArgumentError (no id given)" when it calls super. I know this can happen if I modify the value of "methodname" but I don't. Any ideas?


Use routing instead. Put this as the last route:

code:
map.connect "*anything", :controller => "error", :action => "index"
You end up having to add a new controller, but you get some decent control, instead of a magic method_missing in application_controller.

chemosh6969
Jul 3, 2004

code:
cat /dev/null > /etc/professionalism

I am in fact a massive asswagon.
Do not let me touch computer.
Just starting out with this and my end goal is to get a web gui with my oracle db and thought I'd give rails a try to see how easy it is. So far, I've managed to get everything installed and got the connections to the db working fine.

All the tutorials I've found so far want me to use scaffold and then migrate. What I'd trying to do is get this working with an existing table with data already in it, so I don't want to make something new. I've tried just doing a scaffold based off an existing table but figured out that's not the way to do it.

Is there a tutorial out there that shows what I want to do or am I missing something obvious?

edit: Or I'm just going in the completely wrong direction with this.

chemosh6969 fucked around with this message at 19:37 on Apr 16, 2009

Sewer Adventure
Aug 25, 2004
No need to make any migrations if the tables are pre-existing, models will automatically be filled with data based on the contents of the fields. If you have a table called users then run "script/generate model user" and delete the migration file from db/migrations. Then if you type script/console and then enter User.first it should return the first user from your database

chemosh6969
Jul 3, 2004

code:
cat /dev/null > /etc/professionalism

I am in fact a massive asswagon.
Do not let me touch computer.
That got me closer. I did script/generate model YEAR1, but when I tried to pull the first record it died from trying to pull it from table YEAR1s

manero
Jan 30, 2006

Oh god yes:

http://weblog.rubyonrails.org/2009/4/16/phusion-announces-passenger-for-nginx

hmm yes
Dec 2, 2000
College Slice
Has anyone used hpricot or similar to screen scrape pages that are heavy on ajax/javascript? Right now all I am getting returned is the ol 'your browser needs to support javascript' message when I try to pull down a page.

NotShadowStar
Sep 20, 2000

chemosh6969 posted:

That got me closer. I did script/generate model YEAR1, but when I tried to pull the first record it died from trying to pull it from table YEAR1s

Use ActiveRecord without Rails first, just connect using AR and figure out what you need to do from there, then take that knowledge back into Rails. I learned AR way before I touched a Rails app, it helps.

atastypie posted:

Has anyone used hpricot or similar to screen scrape pages that are heavy on ajax/javascript? Right now all I am getting returned is the ol 'your browser needs to support javascript' message when I try to pull down a page.

Try WWW:Mechanize instead. I use it to interact with a javascript-based login integration site, but I didn't want to redirect to it so I wrapped in in a class that uses Mechanize instead.

Evil Trout
Nov 16, 2004

The evilest trout of them all

chemosh6969 posted:

That got me closer. I did script/generate model YEAR1, but when I tried to pull the first record it died from trying to pull it from table YEAR1s

The problem here is that Rails is heavy on convention over configuration. In other words, it assumes that if a model is named Office, the table in the database will be named offices.

Of course this is less useful for existing databases but not hard to work around. You can still generate a model called Year1 -- but you'll have to add a line to the year1.rb file:

set_table_name "year1"

See http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M002231

chemosh6969
Jul 3, 2004

code:
cat /dev/null > /etc/professionalism

I am in fact a massive asswagon.
Do not let me touch computer.

Evil Trout posted:

The problem here is that Rails is heavy on convention over configuration. In other words, it assumes that if a model is named Office, the table in the database will be named offices.

Of course this is less useful for existing databases but not hard to work around. You can still generate a model called Year1 -- but you'll have to add a line to the year1.rb file:

set_table_name "year1"

See http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M002231

Thanks for the info. Now I just hope I don't run into anymore problems from it assuming things that end up being wrong.

Adolf Hitler
Feb 12, 2003
I'm trying to learn Ruby--coming from Perl--and I decided that there would be no better way than to attempt a weird project from scratch in a new language.

So, here I am. I'm trying to create a data warehouse with the bulk of the data being searchable from a web interface. What I've done so far is at:

http://github.com/aitrus/usrsys/tree/master

Before I try to explain myself, my goals are:

1.) Place account/group data from various operating systems / servers into tables
2.) Place associations from HR to those accounts into tables
3.) Use this data to report on user accounts (searching) and to track *new* changes to system accounts/groups as they happen, day-to-day.

The database I'm building has a lot of purposes. In fact, I built it differently some time ago--with the purpose of performing system cleanup. I did it with SQLite and the tables were more visual (ie, Separate UNIX table for end-user accounts, application accounts, and "unknown" accounts; repeat for each OS). But that's not good design for legitimate databases.

So, I decided to pursue this with Ruby (because co-workers love the poo poo out of it) because my web programming knowledge was stuck in 1998.



I'm using "acts_as_revisable" so I can track changes across various entries / attributes. This is desirable, because engineering groups decide to make chnages to production accounts without following procedures. I feel for them (100%) but we're the ones who get in trouble when they gently caress up. So they don't get to do that anymore.



My biggest issue now is with the design of how I present this information. I know how I want it to look. In fact, I can write the webpage and hard code column names (etc) and make it work all peachy. But that's not what I want. I want to keep the administration of this system simple (after I make this prod-worthy). I would really like to keep people out of dealing with programming issues--or make the administration of that a GUI (web) interface.



Also, lots of AJAX APIs do a lot of work behind the scenes that saves me a lot of trouble. Sorta. ActiveScaffold is neat if I don't actually want to do anything with it. If I could somehow tweak what I've done with it--so far--to improve searching and other (sorta basic) options....... I'd be so much happier.

Versus Boredom
Sep 20, 2006
Hello RoR experts!

I'm currently doing a advertising/marketing internship for an internet start-up company- last night my boss told me he wants me to get a basic grasp of RoR to run some scripts, specifically for Twitter (we have a lot of active followers there since this is a resume posting website). He has the script and it's mainly going to be a copy paste (?) but he wants me to do start by doing, what I guess is the standard first application- "Hello, World".

Only problem is I have zero knowledge on how any of this works. I've never used the Terminal on my mac before and each walkthrough I've tried to slowly go through has left me with nothing to show for it. I've been at it all morning, and after reading CoC I've decided that when I teach myself a programming language this summer, it will be Python. haha...

Ok so back to my question. Can someone give me a supernewb guide to Hello, World?

dustgun
Jun 20, 2004

And then the doorbell would ring and the next santa would come
http://guides.rubyonrails.org/getting_started.html is what I'd recommend at this point. If you need something more realtime than a forum for help, jump into IRC and ask if anyone can help you with sticking points.

NotShadowStar
Sep 20, 2000
If you've never done any web development ever, Rails is going to be really painful to learn and you're going to make a terrible app. Keep this in mind.

dustgun
Jun 20, 2004

And then the doorbell would ring and the next santa would come
Actually, wait. Running scripts and RoR don't go together very well at all because that's not what RoR is really for. What exactly does he want you to do, and are you sure he wasn't just asking you to do it in Ruby?

Versus Boredom
Sep 20, 2006
Yeah I noticed that when I was researching rails this morning- this is for building apps, not running scripts. I just talked to him about it over dinner and he said it was for sure RoR and it's pretty much copy/pasting a script to automate Twitter. What exactly does it do? No idea.

Pardot
Jul 25, 2001




Here is a twitter gem. It looks like it supports oauth, and it's had recent updates. I haven't used it, but I'd check this out out first: jnunemaker-twitter

First Time Caller
Nov 1, 2004

Pardot posted:

Here is a twitter gem. It looks like it supports oauth, and it's had recent updates. I haven't used it, but I'd check this out out first: jnunemaker-twitter

I used this to make a really lovely desktop wxRuby twitter client. It works well enough.

Operation Atlas
Dec 17, 2003

Bliss Can Be Bought

theEZkill posted:

Yeah I noticed that when I was researching rails this morning- this is for building apps, not running scripts. I just talked to him about it over dinner and he said it was for sure RoR and it's pretty much copy/pasting a script to automate Twitter. What exactly does it do? No idea.

You can have a Ruby script that doesn't use Rails, and call it from the command line.

Bathroompants
Aug 19, 2002
I'm really new to rails, so please don't take it too hard on me if I'm trying to do something really dumb.

Is there any way to have my rails installation on my computer (using rake db:migrate) do operations on my webserver's mysql database?

I have the database.yaml file set up that the host is the address of my server's mysql installation along with the username and password and everything, but when I try to use rake db:migrate on my machine the error it gives me uses my IP and not that of the servers.

Is there a configuration file somewhere that I'm missing? Or am I doing this a completely backwards way?

Adolf Hitler
Feb 12, 2003
Oh my god, why doesn't Hobo support rails 2.3.2? I'm going to shoot myself in the head.

The Journey Fraternity
Nov 25, 2003



I found this on the ground!

Adolf Hitler posted:

Oh my god, why doesn't Hobo support rails 2.3.2? I'm going to shoot myself in the head.

Have you looked into its bleeding edge? According to their blog, they're prepping for a 1.0 release that might scratch your 2.3.2 itch.

Jaded Burnout
Jul 10, 2004


Bathroompants posted:

I'm really new to rails, so please don't take it too hard on me if I'm trying to do something really dumb.

Is there any way to have my rails installation on my computer (using rake db:migrate) do operations on my webserver's mysql database?

I have the database.yaml file set up that the host is the address of my server's mysql installation along with the username and password and everything, but when I try to use rake db:migrate on my machine the error it gives me uses my IP and not that of the servers.

Is there a configuration file somewhere that I'm missing? Or am I doing this a completely backwards way?

This is probably not the best way to do this.

The usual method of working with rails is to do all development locally on your machine, using a local database like sqlite, and then have your production server access its own database, usually something more robust like mysql or postgres.

If you really need to use a remote db (e.g. if you really can't host the site on a rails capable server or you have a seperate db server) you can use the host and port parameters like so:

code:
development:
  adapter: mysql
  database: database
  username: username
  password: password
  host: host.example.com
  port: 3306
Bear in mind your environment at the time, by default on your local host rails will load "development". If you need to force production (say if you are using your local machine as your substitute webserver) you specify the environment either on commandline (script/server -e production) or in your apache settings.

Versus Boredom
Sep 20, 2006
deleted

Versus Boredom fucked around with this message at 01:09 on Apr 30, 2009

dustgun
Jun 20, 2004

And then the doorbell would ring and the next santa would come
What do you need to tackle? Installing ruby? Installing the gems? Using the script?
Maybe if you take this to the general questions thread you'd have more luck.

Versus Boredom
Sep 20, 2006

dustgun posted:

What do you need to tackle? Installing ruby? Installing the gems? Using the script?
Maybe if you take this to the general questions thread you'd have more luck.

Pretty much all of that- aside from Installing ruby. General question thread a better place?

wunderbread384
Jun 24, 2004
America's favorite bread

Bathroompants posted:

I'm really new to rails, so please don't take it too hard on me if I'm trying to do something really dumb.

Is there any way to have my rails installation on my computer (using rake db:migrate) do operations on my webserver's mysql database?

I have the database.yaml file set up that the host is the address of my server's mysql installation along with the username and password and everything, but when I try to use rake db:migrate on my machine the error it gives me uses my IP and not that of the servers.

Is there a configuration file somewhere that I'm missing? Or am I doing this a completely backwards way?

If you're just running migrations (rake db:migrate) then you can do this to the production environment, which I assume is your webserver's database, by doing "rake db:migrate RAILS_ENV=production".

This will run any migrations on your local computer but connect to the production database.

Edit: Just realized that might be confusing. Your database.yml file probably has 3 different environments in it, production, test, and development. Development is probably set to your local machine, and rake will use development by default unless you tell it not to.

wunderbread384 fucked around with this message at 02:30 on Apr 28, 2009

Jargon
Apr 22, 2003

Adolf Hitler posted:

Oh my god, why doesn't Hobo support rails 2.3.2? I'm going to shoot myself in the head.

I just started using Hobo too and I am going to shoot myself in the head trying to figure out DRYML.

KarmaticStylee
Apr 21, 2007

Aaaaaughibbrgubugbugrguburgle!
What rails hosting providers would you recommend? I am looking for something under $30/month if possible.

http://www.hostingrails.com/ sounds good. Any experience with them?

KarmaticStylee fucked around with this message at 04:03 on Apr 28, 2009

Jargon
Apr 22, 2003

KarmaticStylee posted:

What rails hosting providers would you recommend? I am looking for something under $30/month if possible.

http://www.hostingrails.com/ sounds good. Any experience with them?

I've been using Slicehost ($20 for an Ubuntu VPS with 256MB ram, enough to run a Rails site with light to moderate traffic), and it's a great value if you don't mind getting your hands dirty with a bare Linux box.

Although with Rails Machine's Moonshine plugin (installs Ruby, Apache, Passenger, MySQL, and your gems, and sets it all up for you), you really don't have to do much other than secure your box.

Also that's a referral link up above so you can go to http://slicehost.com if you're a commie pinko who hates capitalism

Jargon fucked around with this message at 04:48 on Apr 28, 2009

NotShadowStar
Sep 20, 2000

theEZkill posted:

Hey guys- thanks for the advice. I just got that twitter script. Like I said before I'm a complete newb at this and care barley pull off a "Hello World".


Any tips on how I should tackle this?

Yeah try and figure out what the gently caress is going on. Why is Mechanize needed for a Twitter app? Also what you have going on looks far more convoluted that what it should be. What is this Ruby program, can you show some of it or something? This smells of something designed by someone who used to be a Java person and is making things way way way overcomplicated.

prom candy
Dec 16, 2005

Only I may dance

KarmaticStylee posted:

What rails hosting providers would you recommend? I am looking for something under $30/month if possible.

http://www.hostingrails.com/ sounds good. Any experience with them?

Slicehost for sure. There are a lot of guides out there on how to get up and running with them, and really part of the Rails experience involves figuring out how to set it up. Luckily for you it's gotten a hell of a lot easier over the past few years. I don't miss configuring dispatch.fcgi one bit.

prom candy
Dec 16, 2005

Only I may dance

NotShadowStar posted:

Why is Mechanize needed for a Twitter app?

It probably actually logs into Twitter rather than using the API.

KarmaticStylee
Apr 21, 2007

Aaaaaughibbrgubugbugrguburgle!
Okay, so if I went with slicehost and used it to develop apps for clients... then they needed an affordable host.. how could I easily move my app to something affordable? (i.e. closer to godaddy pricing)

edit: nevermind.. I could host it myself I guess.. wasn't thinking

KarmaticStylee fucked around with this message at 22:19 on Apr 28, 2009

Jargon
Apr 22, 2003

KarmaticStylee posted:

Okay, so if I went with slicehost and used it to develop apps for clients... then they needed an affordable host.. how could I easily move my app to something affordable? (i.e. closer to godaddy pricing)

edit: nevermind.. I could host it myself I guess.. wasn't thinking

If you have multiple clients with low-to-medium traffic websites, you can spend $38 or $70 a month for a bigger slice, then charge the clients for hosting. If you're creative with Passenger pools and timeouts, you can balance it out so that you can squeeze quite a few Rails apps on one box and actually turn a profit while still giving them good performance.

Bathroompants
Aug 19, 2002

Arachnamus posted:

This is probably not the best way to do this.

wunderbread384 posted:



Thanks for the responses guys, I figured out that I was doing things the hard way. Trying to learn subversion and rails at the same time had me very confused but I've worked out that step of the problem and have gotten to be able to start messing around with rails =)

Adbot
ADBOT LOVES YOU

KarmaticStylee
Apr 21, 2007

Aaaaaughibbrgubugbugrguburgle!

Jargon posted:

If you have multiple clients with low-to-medium traffic websites, you can spend $38 or $70 a month for a bigger slice, then charge the clients for hosting. If you're creative with Passenger pools and timeouts, you can balance it out so that you can squeeze quite a few Rails apps on one box and actually turn a profit while still giving them good performance.

I'm guessing that I will make the money from clients to scale without much $$$ worry

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