Please help --> Getting error ERROR NoMethodError: private method `gsub!' called for #<Class:0x47a8e38>

103 views
Skip to first unread message

Sony Thomas

unread,
Jul 21, 2010, 2:39:29 AM7/21/10
to Ruby on Rails: Talk
[2010-07-21 11:35:18] ERROR NoMethodError: private method `gsub!'
called for #<Class:0x47a8e38>
C:/Applns/Ruby187/lib/ruby/1.8/webrick/htmlutils.rb:16:in
`escape'
C:/Applns/Ruby187/lib/ruby/1.8/webrick/httpresponse.rb:232:in
`set_error'
C:/Applns/Ruby187/lib/ruby/gems/1.8/gems/rails-2.2.3/lib/
webrick_server.rb:94:in `handle_file'
C:/Applns/Ruby187/lib/ruby/gems/1.8/gems/rails-2.2.3/lib/
webrick_server.rb:73:in `service'
C:/Applns/Ruby187/lib/ruby/1.8/webrick/httpserver.rb:104:in
`service'
C:/Applns/Ruby187/lib/ruby/1.8/webrick/httpserver.rb:65:in
`run'
C:/Applns/Ruby187/lib/ruby/1.8/webrick/server.rb:173:in
`start_thread'
C:/Applns/Ruby187/lib/ruby/1.8/webrick/server.rb:162:in
`start'
C:/Applns/Ruby187/lib/ruby/1.8/webrick/server.rb:162:in
`start_thread'
C:/Applns/Ruby187/lib/ruby/1.8/webrick/server.rb:95:in `start'
C:/Applns/Ruby187/lib/ruby/1.8/webrick/server.rb:92:in `each'
C:/Applns/Ruby187/lib/ruby/1.8/webrick/server.rb:92:in `start'
C:/Applns/Ruby187/lib/ruby/1.8/webrick/server.rb:23:in `start'
C:/Applns/Ruby187/lib/ruby/1.8/webrick/server.rb:82:in `start'
C:/Applns/Ruby187/lib/ruby/gems/1.8/gems/rails-2.2.3/lib/
webrick_server.rb:60:in `dispatch'
C:/Applns/Ruby187/lib/ruby/gems/1.8/gems/rails-2.2.3/lib/
commands/servers/webrick.rb:66
C:/Applns/Ruby187/lib/ruby/site_ruby/1.8/rubygems/
custom_require.rb:31:in `gem_original_require'
C:/Applns/Ruby187/lib/ruby/site_ruby/1.8/rubygems/
custom_require.rb:31:in `require'
C:/Applns/Ruby187/lib/ruby/gems/1.8/gems/activesupport-2.2.3/
lib/active_support/dependencies.rb:153:in
`require'
C:/Applns/Ruby187/lib/ruby/gems/1.8/gems/activesupport-2.2.3/
lib/active_support/dependencies.rb:521:in
`new_constants_in'
C:/Applns/Ruby187/lib/ruby/gems/1.8/gems/activesupport-2.2.3/
lib/active_support/dependencies.rb:153:in
`require'
C:/Applns/Ruby187/lib/ruby/gems/1.8/gems/rails-2.2.3/lib/
commands/server.rb:49
C:/Applns/Ruby187/lib/ruby/site_ruby/1.8/rubygems/
custom_require.rb:31:in `gem_original_require'
C:/Applns/Ruby187/lib/ruby/site_ruby/1.8/rubygems/
custom_require.rb:31:in `require'
script/server:3
127.0.0.1 - - [21/Jul/2010:11:35:18 India Standard Time] "GET / HTTP/
1.1" 500 338

kannav rajeev

unread,
Jul 21, 2010, 3:07:14 AM7/21/10
to rubyonra...@googlegroups.com
Write the code here pleZse

> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To unsubscribe from this group, send email to rubyonrails-ta...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
>
>

--
Thanks:
Rajeev sharma

sony.t...@wipro.com

unread,
Jul 21, 2010, 3:15:24 AM7/21/10
to rubyonra...@googlegroups.com
Just try to "http://localhost:3000/" after starting the webrick server.

:-(

kannav rajeev

unread,
Jul 21, 2010, 3:21:09 AM7/21/10
to rubyonra...@googlegroups.com
sorry i don't think these lines given below are help full to find out error
run "ruby script/server -t"
Goto Yours development log file copy all the text and paste all text
of that file here


--
Thanks:
Rajeev sharma

sony.t...@wipro.com

unread,
Jul 21, 2010, 3:24:37 AM7/21/10
to rubyonra...@googlegroups.com
I got invalid option for "-t"

Please check below

ruby script/server -t
=> Booting WEBrick...
server: invalid option: -t
=> Rails 2.2.3 application started on http://0.0.0.0:3000
=> Ctrl-C to shutdown server; call with --help for options
[2010-07-21 12:43:28] INFO WEBrick 1.3.1
[2010-07-21 12:43:28] INFO ruby 1.8.7 (2010-01-10) [i386-mingw32]
[2010-07-21 12:43:28] INFO WEBrick::HTTPServer#start: pid=2720
port=3000

-----Original Message-----
From: rubyonra...@googlegroups.com
[mailto:rubyonra...@googlegroups.com] On Behalf Of kannav rajeev
Sent: Wednesday, July 21, 2010 12:51 PM
To: rubyonra...@googlegroups.com
Subject: Re: [Rails] Please help --> Getting error ERROR NoMethodError:
private method `gsub!' called for #<Class:0x47a8e38>


--
Thanks:
Rajeev sharma

--

sony.t...@wipro.com

unread,
Jul 21, 2010, 3:31:38 AM7/21/10
to rubyonra...@googlegroups.com
One more point like I have tried to configure my DB in database.yml.

It was

development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000

I changed to

development:
adapter: mysql
database: library_development
username: root
password: *****
host: localhost
pool: 5
timeout: 5000

Any problem with this ?

-----Original Message-----
From: rubyonra...@googlegroups.com
[mailto:rubyonra...@googlegroups.com] On Behalf Of kannav rajeev
Sent: Wednesday, July 21, 2010 12:51 PM
To: rubyonra...@googlegroups.com
Subject: Re: [Rails] Please help --> Getting error ERROR NoMethodError:
private method `gsub!' called for #<Class:0x47a8e38>


--
Thanks:
Rajeev sharma

--

kannav rajeev

unread,
Jul 21, 2010, 3:34:40 AM7/21/10
to rubyonra...@googlegroups.com
its yours first application on rails ?

--
Thanks:
Rajeev sharma

sony.t...@wipro.com

unread,
Jul 21, 2010, 4:57:56 AM7/21/10
to rubyonra...@googlegroups.com
S


:-)

kannav rajeev

unread,
Jul 22, 2010, 1:06:34 AM7/22/10
to rubyonra...@googlegroups.com
use instant rails if possible go back on ruby on rails installation again

Amir Z.

unread,
Apr 25, 2012, 3:13:24 AM4/25/12
to rubyonra...@googlegroups.com
I am working with railspace social networking application. I did login
logout registration process in it but as i am introducing the concept
for remember me then stuck in the problem. it is showing the following
error.

private method `gsub' called for 4:Fixnum

C:/Users/Amir/Downloads/IR/ruby/lib/ruby/1.8/cgi.rb:342:in `escape'
C:/Users/Amir/Downloads/IR/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/cgi_ext/cookie.rb:73:in
`to_s'
C:/Users/Amir/Downloads/IR/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/cgi_ext/cookie.rb:73:in
`collect'
C:/Users/Amir/Downloads/IR/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/cgi_ext/cookie.rb:73:in
`to_s'
C:/Users/Amir/Downloads/IR/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/cookies.rb:80:in
`set_cookie'
C:/Users/Amir/Downloads/IR/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/cookies.rb:65:in
`[]='
app/controllers/user_controller.rb:27:in `login'

Please help me out. Any help is appreciated

Thanks

Amir

--
Posted via http://www.ruby-forum.com/.

Colin Law

unread,
Apr 25, 2012, 3:26:06 AM4/25/12
to rubyonra...@googlegroups.com
It is telling you the line that the problem is (line 27 in
user_controller.rb, which is a bit odd, I would have expected it to be
called users_controller.rb not user_controller.rb), and the error
tells you that you are calling gsub, but the object you are calling it
on is a number instead of a valid object that understands the method
gsub. Have a look at that line. Then if you cannot see the problem
have a look at the Rails Guide on debugging for suggestions on how to
debug your code.

Colin

Amir Z.

unread,
Apr 25, 2012, 3:53:59 AM4/25/12
to rubyonra...@googlegroups.com
Thanks Colin
we are calling it as an object. Please find my login code below.

def login
if request.get?
@user = User.new(:remember_me => cookies[:remember_me] || "0")
elsif param_posted?(:user)
@user = User.new(params[:user])
user = User.find_by_screen_name_and_password(@user.screen_name,
@user.password)
if user
user.login!(session)
if @user.remember_me == "1"
cookies[:remember_me] = { :value => "1",
:expires => 10.years.from_now }
user.authorization_token = user.id
user.save!
cookies[:authorization_token] = { (line no. 27)
:value => user.authorization_token, (line no. 28)
:expires => 10.years.from_now } (line no. 29)
else
cookies.delete(:remember_me)
cookies.delete(:authorization_token)
end
flash[:notice] = "User #{user.screen_name} logged in!"
redirect_to_forwarding_url
else
@user.clear_password!
flash[:notice] = "Invalid screen name/password combination"
end
end
end

Colin Law

unread,
Apr 25, 2012, 3:57:45 AM4/25/12
to rubyonra...@googlegroups.com
On 25 April 2012 08:53, Amir Z. <li...@ruby-forum.com> wrote:
> Thanks Colin
> we are calling it as an object. Please find my login code below.

Which is the line generating the error?

Colin

Amir Z.

unread,
Apr 25, 2012, 6:19:24 AM4/25/12
to rubyonra...@googlegroups.com
Error showing in line no. 27

Please find below the error trace

C:/Users/Amir/Downloads/IR/ruby/lib/ruby/1.8/cgi.rb:342:in `escape'
C:/Users/Amir/Downloads/IR/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/cgi_ext/cookie.rb:73:in
`to_s'
C:/Users/Amir/Downloads/IR/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/cgi_ext/cookie.rb:73:in
`collect'
C:/Users/Amir/Downloads/IR/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/cgi_ext/cookie.rb:73:in
`to_s'
C:/Users/Amir/Downloads/IR/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/cookies.rb:80:in
`set_cookie'
C:/Users/Amir/Downloads/IR/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/cookies.rb:65:in
`[]='
app/controllers/user_controller.rb:27:in `login'

--
Posted via http://www.ruby-forum.com/.

Matt Jones

unread,
Apr 26, 2012, 8:24:40 AM4/26/12
to rubyonra...@googlegroups.com


On Wednesday, 25 April 2012 03:53:59 UTC-4, Ruby-Forum.com User wrote:
Thanks Colin
we are calling it as an object. Please find my login code below.

def login
if request.get?
@user = User.new(:remember_me => cookies[:remember_me] || "0")
elsif param_posted?(:user)
@user = User.new(params[:user])
user = User.find_by_screen_name_and_password(@user.screen_name,
@user.password)
if user
user.login!(session)
if @user.remember_me == "1"
cookies[:remember_me] = { :value => "1",
:expires => 10.years.from_now }
  user.authorization_token = user.id

This is where things go wrong - user.id is not a string.
 
user.save!
cookies[:authorization_token] = {              (line no. 27)
:value => user.authorization_token,            (line no. 28)

The cookie value here *must* be a string - passing in a Fixnum is what's causing the error. The original RailsSpace code sets the token to a hashed string, not the user's id.

Regarding RailsSpace: that book is wildly out-of-date (I note that you're using Rails 2.0.2 from the traces above) and does some things that were extremely questionable even for that time period. For instance, storing passwords in cleartext in the DB is strongly discouraged - it's led to *massive* security breaches over the years on other web applications.

Here's an updated tutorial from the RailsSpace authors, so you're not learning the 2007 version of the framework:


--Matt Jones
Reply all
Reply to author
Forward
0 new messages