Forum: Ruby on Rails cant convert integer to string

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
zbyte pepsi-hola (Guest)
on 2006-01-25 10:56
(Received via mailing list)
I've experimented around and have ran out of ideas, here's the message:

 TypeError in True_false_questions#list

can't convert String into Integer

RAILS_ROOT: script/../config/..
Application Trace <http://zbyte32:3000/true_false_questions/list/0#> |
Framework
Trace <http://zbyte32:3000/true_false_questions/list/0#> | Full
Trace<http://zbyte32:3000/true_false_questions/list/0#>

./script/../config/../app/controllers/true_false_questions_controller.rb:9:in
`[]'

here's the code snippet:


class TrueFalseQuestionsController < ApplicationController
  def index
    list
    render :action => 'list'
  end

  def list
    if params[:id]
      @true_false_question_pages, @true_false_questions = paginate
TrueFalseQuestion.find_all["tests_id = ?"+ params[:id]], :per_page => 10
    else
      @true_false_question_pages, @true_false_questions = paginate
:true_false_questions, :per_page => 10
    end
  end

basically vist the url: http://zbyte32:3000/true_false_questions/list/0

any suggestions would be much apreciated. Thank you.
Alex Y. (Guest)
on 2006-01-25 11:08
(Received via mailing list)
I think you want:

if params[:id]
   @true_false_question_pages, @true_false_questions =
     paginate TrueFalseQuestion.find( :all,
       :conditions => ["tests_id = ?", [params[:id]]]),
         :per_page => 10

Or better, if you've got the associations set up:

if params[:id]
   @true_false_question_pages, @true_false_questions =
     paginate Test.find(params[:id]).true_false_questions,
       :per_page => 10

--
Alex
zbyte pepsi-hola (Guest)
on 2006-01-25 11:17
(Received via mailing list)
hmm, now i get:

 NameError in True_false_questions#list

"#<TrueFalseQuestion:0xb73d616c>" is not a valid constant name!

RAILS_ROOT: script/../config/..
Application Trace <http://zbyte32:3000/true_false_questions/list/0#> |
Framework
Trace <http://zbyte32:3000/true_false_questions/list/0#> | Full
Trace<http://zbyte32:3000/true_false_questions/list/0#>

/usr/lib/ruby/gems/1.8/gems/activesupport-1.2.5/lib/active_support/core_ext/integer/../../inflector.rb:145:in
`constantize'
/usr/lib/ruby/gems/1.8/gems/activesupport-1.2.5/lib/active_support/core_ext/string/inflections.rb:52:in
`constantize'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/pagination.rb:186:in
`paginator_and_collection_for'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/pagination.rb:124:in
`paginate'
./script/../config/../app/controllers/true_false_questions_controller.rb:9:in
`list'


just to clariy, tests_id is a foreign key.
zbyte pepsi-hola (Guest)
on 2006-01-25 21:23
(Received via mailing list)
I am sorry, but I am rather new to ruby, I am not exactly sure what is
wrong
with the code you gave me, I am sure I typed it in properly
Alex Y. (Guest)
on 2006-01-25 21:29
(Received via mailing list)
zbyte pepsi-hola wrote:
> I am sorry, but I am rather new to ruby, I am not exactly sure what is
> wrong with the code you gave me, I am sure I typed it in properly
I was just typing from memory, so there may well be a blooper in there
somewhere.  Was it the first or second that you tried?  I'm guessing it
was the second...  Can you post your true_false_question.rb and test.rb
files?

--
Alex
zbyte pepsi-hola (Guest)
on 2006-01-25 21:32
(Received via mailing list)
i couldn't find what was wrong, but i tried a different approach and it
workd:

@true_false_question_pages, @true_false_questions = paginate
:true_false_questions, :conditions => ["tests_id = ?", params[:id]],
:per_page => 10
zbyte pepsi-hola (Guest)
on 2006-01-26 03:37
(Received via mailing list)
I tried both :) the error you see is from the first. I am currently at
school but i will post the files once i get home.
This topic is locked and can not be replied to.