Re: [Rails] ActiveRecord::AssociationTypeMismatch in UsersController#update
On 9 June 2012 03:36, Paul McGuane <lists@ruby-forum.com> wrote:
> 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'
Perhaps it would be useful if you told us which is line 66.
>
>
> 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])
In case I have made a lucky guess and it is this line then look in
development.log to see what params[:user] will be. Also have a look
at the Rails Guide on debugging to see techniques that can be used to
debug your code.
Colin
> 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 post to this group, send email to rubyonrails-talk@googlegroups.com.
> To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
>
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home