On Nov 10, 2005, at 8:52 PM, burak / lysurge.net wrote: > Hey, > > I'm VERY new to Ruby on Rails. I was wondering if somebody could help > me out by clearing up a few things. I've been noticing that stuff I > try > in Ruby will work fine, but the same code in a Rails app won't > work. So > let me post a few lines of code here, and maybe (hopefully) somebody > can help me figure out why it works in a ruby shell thingy and not > in a > rails app. > > Here's the Ruby: > > require 'mechanize' > > agent = WWW::Mechanize.new > > agent.user_agent_alias = 'Windows IE 6' > > page = > agent.get('https://login.yahoo.com/config/login? > login=xxxxx&passwd=xxxxx&tries=1&.src=srch&.lg=us&partner=&submit=Sign > +In&.done=http://submit.search.yahoo.com/free/request') > > page = > agent.get('http://submit.search.yahoo.com/free/request? > class=Submit&pass=1&url=http%3A//wherever.net') > > p page > > > When this runs, it works just fine. When I try it in a rails app, as > posted below, it doesn't. I'll post the error message too. > > class EnginesController < ApplicationController > > require 'net/http' > require 'net/https' > require 'uri' > require 'mechanize' > > def yahoo > > agent = WWW::Mechanize.new > > agent.user_agent_alias = 'Windows IE 6' > > page = agent.get('https://login.yahoo.com/config/login? > login=xxxxx&passwd=xxxxx&tries=1&.src=srch&.lg=us&partner=&submit=Sign > +In&.done=http://submit.search.yahoo.com/free/request') > > page = > agent.get('http://submit.search.yahoo.com/free/request? > class=Submit&pass=1&url=http%3A//wherever.net') > > @data=page > end > end > > (@data is just a variable that gets send to the output page) > I then navigate to the correct page and I get this error: > > undefined method `add_header' for #<Net::HTTP::Get GET> > > I really don't understand. There are a few other errors that I get in > Rails that I don't understand either; a lot having to do with > databases. I'm pretty sure both my Ruby and Rails installations are > current. I greatly appreciate any help and advice you can give. > > Thanks, > Burak Burak- I think what is happening is that rails is munging with the request object and causing a conflict between ActionController and WWW:::Mechanize. What I would do is move the mechanize stuff into its own model class and just call its methods from your controller. But just make your class by itself and don't inherit from ApplicationController. This way you probably won't get a conflict between the two functionalities. Cheers- -Ezra Zygmuntowicz WebMaster Yakima Herald-Republic Newspaper ezra / yakima-herald.com 509-577-7732