TicketType(#70316537311800) expected, got String(#10085740) app/controllers/reasons_controller.rb:44:in `new'' app/controllers/reasons_controller.rb:44:in `create'' View: <%= f.label :ticket_type %><br /> <%= f.select :ticket_type, TicketType.all.collect {|t| [ t.description, t.description]}, {:include_blank => "Please select one"}, :method => ''get''%> Controller: @reason = Reason.new(params[:reason]) respond_to do |format| if @reason.save format.html { redirect_to manage_tickets_path, notice: ''Reason was successfully created.'' } etc Model: class Reason < ActiveRecord::Base validates :description, :ticket_type, :presence => true attr_accessible :description, :ticket_type belongs_to :ticket_type, :foreign_key => :ticket_type end class TicketType < ActiveRecord::Base attr_accessible :description has_many :reasons, :foreign_key => :ticket_type end I have read the "Kitchen" posting about the same error, the only problem is i am using a description, not ID. Changing the form just gives errors, any help would be greatly appreciated. Thanks! -- 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 unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
On 27 February 2013 19:56, Colton Pl <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> TicketType(#70316537311800) expected, got String(#10085740) > > app/controllers/reasons_controller.rb:44:in `new'' > app/controllers/reasons_controller.rb:44:in `create'' > > View: > > <%= f.label :ticket_type %><br /> > <%= f.select :ticket_type, TicketType.all.collect {|t| [ t.description, > t.description]}, {:include_blank => "Please select one"}, :method => > ''get''%> > > Controller: > > @reason = Reason.new(params[:reason]) > > respond_to do |format| > if @reason.save > format.html { redirect_to manage_tickets_path, notice: ''Reason > was successfully created.'' } > etc > > Model: > > class Reason < ActiveRecord::Base > validates :description, :ticket_type, :presence => true > attr_accessible :description, :ticket_type > > belongs_to :ticket_type, :foreign_key => :ticket_typeIf you have the foreign key column called ticket_type and also belongs_to ticket_type, then when you do @reason.ticket_type how is rails going to know whether you want the value of the column or the associated object? Best to stick to the conventions and call the column ticket_type_id. By the way, when posting an error it is a good idea to tell us which line is the line the error refers to (ie which is line 44 in this case) in order to save us having to work it out ourselves. Colin> end > > class TicketType < ActiveRecord::Base > attr_accessible :description > > has_many :reasons, :foreign_key => :ticket_type > end >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
That worked perfectly. Thanks alot for the help, and ill keep the line #''s in mind for next time -- 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 unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.