I have a series of countries listed in a table in the following form:
id, country_name
I want to pull these in and I'm trying everything under the sun from a
variety of different peoples pages. I just cannot get anything working
at all. I have tried pulling all the records in the the ctrl.rb file
with:
@country_list = Country.find_all
I get the following:
undefined method `find_all' for #<Class:0xb657a3a8>
I have put this in the following method
def new
@usr = Usr.new
@country_list = Country.find_all
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @usr }
end
end
I'm not fussy about the methodology, I simply want a drop down list the
easiest and simplest way...I have tried a number of other approaching,
but I wonder if there are problems with RoR versions?
I have a series of countries listed in a table in the following form:
id, country_name
I want to pull these in and I'm trying everything under the sun from a
variety of different peoples pages. I just cannot get anything working
at all. I have tried pulling all the records in the the ctrl.rb file
with:
@country_list = Country.find_all
I get the following:
undefined method `find_all' for #<Class:0xb657a3a8>
I have put this in the following method
def new
@usr = Usr.new
@country_list = Country.find_all
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @usr }
end
end
I'm not fussy about the methodology, I simply want a drop down list the
easiest and simplest way...I have tried a number of other approaching,
but I wonder if there are problems with RoR versions?
You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.map
What happens if, rather than using collection select, you just display
the id and country name for each item in @country list? Doing that
will prove that the data is ok. I presume that the table has a
country_name column.
You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.map
What happens if, rather than using collection select, you just display
the id and country name for each item in @country list? Doing that
will prove that the data is ok. I presume that the table has a
country_name column.
Colin
here is a read-out - the data is there...
Listing countries
Country name
UK Show Edit Destroy
France Show Edit Destroy
Germany Show Edit Destroy
You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.map
What happens if, rather than using collection select, you just display
the id and country name for each item in @country list? Doing that
will prove that the data is ok. I presume that the table has a
country_name column.
Colin
here is a read-out - the data is there...
Listing countries
Country name
UK Show Edit Destroy
France Show Edit Destroy
Germany Show Edit Destroy
Is that from code inserted in the view at the same point as the
collection_select?
Please show the complete error trace and the code around the error,
and confirm which line of code the error is on.
I can see data in the DB, but cannot seem to get this into a drop down.
The controller code does not produce an error. But the errors would seem
to imply that there is no data being pulled in.
You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.map
What happens if, rather than using collection select, you just display
the id and country name for each item in @country list? Doing that
will prove that the data is ok. I presume that the table has a
country_name column.
Colin
here is a read-out - the data is there...
Listing countries
Country name
UK Show Edit Destroy
France Show Edit Destroy
Germany Show Edit Destroy
Is that from code inserted in the view at the same point as the
collection_select?
You replied showing the trace (but not actually as a reply to this
post) but did not answer the above question
the id and country name for each item in @country list? Doing that
UK Show Edit Destroy
France Show Edit Destroy
Germany Show Edit Destroy
Is that from code inserted in the view at the same point as the
collection_select?
You replied showing the trace (but not actually as a reply to this
post) but did not answer the above question
Colin
Problem solved, I had not put the @country_list into the other methods -
such as the index one. This now worked and I can create a drop down
populated from the table.
Now I am presuming the select statement will pop the id into the country
field in my created users table. However I cannot seem to find it in the
actual data tables.
the id and country name for each item in @country list? Doing that
UK Show Edit Destroy
France Show Edit Destroy
Germany Show Edit Destroy
Is that from code inserted in the view at the same point as the
collection_select?
You replied showing the trace (but not actually as a reply to this
post) but did not answer the above question
Colin
Problem solved, I had not put the @country_list into the other methods -
such as the index one. This now worked and I can create a drop down
populated from the table.
Hmm, so the error in new.html.erb was due to the fact that you had not
populated @country_list in the controller#index. I think not.
Now I am presuming the select statement will pop the id into the country
field in my created users table. However I cannot seem to find it in the
actual data tables.
No idea what you are talking about. All a select does is to allow a selection.
Plus also how best to validate drop down boxes?
Validation is nothing to do with how the data are selected. It is
purely a verification of the data as it goes into the db via the
model.