undefined method join

Hey all,

I get an undefined method `join' for #<String NoMethodError.

student.rb   has_one :student_fail   attr_accessor :student_fail_attribute

  #controller   def student_fail   @student = @student.find params[:id]

  def update_student_fail    @student.build_student_fail params[:student][:student_fail_attribute]    if @student.save

  #view   form_for @student do |f| f.collection_select(:student_fail_attribute, StudentFailState.all, :id, :key) end

I don't understand why the error. This is the example that rails documentation gives, which looks very close to mine: collection_select(:post, :author_id, Author.all, :id, :name_with_initial, {:prompt => true})

Hey all,

I get an undefined method `join' for #<String NoMethodError.

One what line does this error occur? Also if you're going to post code, you might as well make it a complete piece of code - what you've posted there isn't syntactically correct ruby.

Fred

Quoting Frederick Cheung <frederick.cheung@gmail.com>:

> Hey all, > > I get an undefined method `join' for #<String NoMethodError. >

join isn't defined for strings. Arrays of strings, yes, a single string, no.

Jeffrey

And it doesn't even makes sense, since join takes an array and returns each element into a String. What would one expect from "Hello, World".join ?

So why does the example in rails guide work and not mine, where I tried to copy as close to it as possible? All I'm trying to do is update another table from a form. Thanks.

Curtis Cooley-3 wrote:

So why does the example in rails guide work and not mine, where I tried to copy as close to it as possible? All I'm trying to do is update another table from a form. Thanks.

Curtis Cooley-3 wrote:

If you show us the walkback, and not just the exception message, maybe somebody will have a better chance to help.

I don't see where join is being called in the code you posted, but one thing that trips me up every once in a while is forgetting :all

Student.find_by_last_name("Jones")

returns a String where

Student.find_all_by_last_name("Jones") or Student.find(:all, :conditions => "last_name = 'Jones'")

returns an Array

join will work on the latter but not the former.