http://api.rubyonrails.org/classes/ActiveRecord/AssociationTypeMismatch.html
I gues it's raise because you don't assign object. You should change it
this way:
<%= select("user", "*team_id*", Team.all.collect { |p| [p.name,
p.id] }, {:include_blank => 'None'}) %>
суббота, 9 июня 2012 г., 6:36:36 UTC+4 пользователь Ruby-Forum.com User
написал:
>
> Hi
> Im trying to link my User model to a Teams model. I seem to be getting
> the following errors. Any help would be great as Im just new to RoR
> Thanks
>
> error
> ActiveRecord::AssociationTypeMismatch in UsersController#update
>
> Team(#2183395560) expected, got String(#2174675960)
> app/controllers/users_controller.rb:67:in `update'
> app/controllers/users_controller.rb:66:in `update'
>
>
> users_controller.rb
> # PUT /users/1
> # PUT /users/1.json
> def update
> @user = User.find(params[:id])
>
> respond_to do |format|
> if @user.update_attributes(params[:user])
> format.html { redirect_to(users_url,
> :notice => "The information for #{@user.first_name}
> #{@user.last_name} was successfully updated.") }
> format.json { head :no_content }
> else
> format.html { render :action => "edit" }
> format.json { render :json => @user.errors, :status =>
> :unprocessable_entity }
> end
> end
> end
>
>
> user.rb
> class User < ActiveRecord::Base
> belongs_to :team
> attr_accessible :team
>
>
> team.rb
> class Team < ActiveRecord::Base
> has_many :users
> has_many :schedules
> attr_accessible :name
> end
>
>
> user/_form.html.erb
> <div class="_25">
> <p>
> <%= f.label :team %>
> <%= select("user", "team", Team.all.collect { |p| [p.name,
> p.id] }, {:include_blank => 'None'}) %>
> </p>
> </div>
>
> --
> Posted via http://www.ruby-forum.com/.
>
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/rubyonrails-talk/-/IAT4Dkdj6v0J.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.