Model Product paperclip erro got String

6 views
Skip to first unread message

Farah

unread,
Nov 25, 2009, 6:11:37 PM11/25/09
to rails-br
Olá pessoal

Estou utilizando um model product que está utilizando o paperclip,
quando tento gravar eu tenho a seguinte resposta

ProductType(#38240380) expected, got String(#20837400)

C:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/
associations/association_proxy.rb:263:in `raise_on_type_mismatch'
C:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/
associations/belongs_to_association.rb:22:in `replace'
C:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/
associations.rb:1278:in `product_type='
C:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/
base.rb:2744:in `send'
C:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/
base.rb:2744:in `attributes='
C:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/
base.rb:2740:in `each'
C:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/
base.rb:2740:in `attributes='
C:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/
base.rb:2438:in `initialize'
D:/santa_rosa_project/app/controllers/products_controller.rb:43:in
`new'
D:/santa_rosa_project/app/controllers/products_controller.rb:43:in
`create'
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.4/lib/action_controller/
base.rb:1331:in `send'
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.4/lib/action_controller/
base.rb:1331:in `perform_action_without_filters'
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.4/lib/action_controller/
filters.rb:617:in `call_filters'
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.4/lib/action_controller/
filters.rb:610:in `perform_action_without_benchmark'
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.4/lib/action_controller/
benchmarking.rb:68:in `perform_action_without_rescue'
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/
core_ext/benchmark.rb:17:in `ms'
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/
core_ext/benchmark.rb:10:in `realtime'
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/
core_ext/benchmark.rb:17:in `ms'
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.4/lib/action_controller/
benchmarking.rb:68:in `perform_action_without_rescue'
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.4/lib/action_controller/
rescue.rb:160:in `perform_action_without_flash'
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.4/lib/action_controller/
flash.rb:146:in `perform_action'
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.4/lib/action_controller/
base.rb:532:in `send'
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.4/lib/action_controller/
base.rb:532:in `process_without_filters'
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.4/lib/action_controller/
filters.rb:606:in `process'
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.4/lib/action_controller/
base.rb:391:in `process'
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.4/lib/action_controller/
base.rb:386:in `call'
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.4/lib/action_controller/
routing/route_set.rb:437:in `call'
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.4/lib/action_controller/
dispatcher.rb:87:in `dispatch'
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.4/lib/action_controller/
dispatcher.rb:121:in `_call'
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.4/lib/action_controller/
dispatcher.rb:130:in `build_middleware_stack'
C:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/
query_cache.rb:29:in `call'
C:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/
query_cache.rb:29:in `call'
C:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/
connection_adapters/abstract/query_cache.rb:34:in `cache'
C:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/
query_cache.rb:9:in `cache'
C:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/
query_cache.rb:28:in `call'
C:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/
connection_adapters/abstract/connection_pool.rb:361:in `call'
C:/ruby/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/head.rb:9:in `call'
C:/ruby/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/methodoverride.rb:
24:in `call'
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.4/lib/action_controller/
params_parser.rb:15:in `call'
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.4/lib/action_controller/
session/cookie_store.rb:93:in `call'
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.4/lib/action_controller/
failsafe.rb:26:in `call'
C:/ruby/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/lock.rb:11:in
`call'
C:/ruby/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/lock.rb:11:in
`synchronize'
C:/ruby/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/lock.rb:11:in
`call'
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.4/lib/action_controller/
dispatcher.rb:114:in `call'
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.4/lib/action_controller/
reloader.rb:34:in `run'
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.4/lib/action_controller/
dispatcher.rb:108:in `call'
C:/ruby/lib/ruby/gems/1.8/gems/rails-2.3.4/lib/rails/rack/static.rb:
31:in `call'
C:/ruby/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/urlmap.rb:46:in
`call'
C:/ruby/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/urlmap.rb:40:in
`each'
C:/ruby/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/urlmap.rb:40:in
`call'
C:/ruby/lib/ruby/gems/1.8/gems/rails-2.3.4/lib/rails/rack/
log_tailer.rb:17:in `call'
C:/ruby/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/content_length.rb:
13:in `call'
C:/ruby/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/handler/webrick.rb:
50:in `service'
C:/ruby/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
C:/ruby/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
C:/ruby/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
C:/ruby/lib/ruby/1.8/webrick/server.rb:162:in `start'
C:/ruby/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
C:/ruby/lib/ruby/1.8/webrick/server.rb:95:in `start'
C:/ruby/lib/ruby/1.8/webrick/server.rb:92:in `each'
C:/ruby/lib/ruby/1.8/webrick/server.rb:92:in `start'
C:/ruby/lib/ruby/1.8/webrick/server.rb:23:in `start'
C:/ruby/lib/ruby/1.8/webrick/server.rb:82:in `start'
C:/ruby/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/handler/webrick.rb:
14:in `run'
C:/ruby/lib/ruby/gems/1.8/gems/rails-2.3.4/lib/commands/server.rb:111
C:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in
`gem_original_require'
C:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in
`require'
script/server:3

Farah

unread,
Nov 25, 2009, 6:14:48 PM11/25/09
to rails-br
Só lembrando que estou usando validates no modelo, mas não entendo o
por que

Farah

unread,
Nov 25, 2009, 6:40:31 PM11/25/09
to rails-br
ActiveRecord::AssociationTypeMismatch in ProductsController#create

Farah

unread,
Nov 25, 2009, 7:06:10 PM11/25/09
to rails-br
Pessoal consegui isolar o problema, eu descobri que o problema todo
está no meu select, mas não sei fazer um select_tag melhor que este.

<p>
<%= f.label "Tipo de produto" %><br />
<%= f.collection_select :product_type, ProductType.find
(:all),:id,:product_type,:prompt =>"Selecione um tipo de produto" %>
</p>

Alguem sabe como criar outro select diferente deste ou há outra
solucao?

Farah

unread,
Nov 25, 2009, 7:48:04 PM11/25/09
to rails-br
Pessoal quebrando a cabeça que agente consegue neh hehehe

Pra quem tiver com o mesmo problema a resposta é simples, DEVE-SE
UTILIZAR O NOME DO CAMPO DO BANCO DE DADOS com _id obrigatoriamente.


Obrigado a todos
Reply all
Reply to author
Forward
0 new messages