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
Tracehttp://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.
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
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
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
Tracehttp://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.
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
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.