2013-07-04 52 views
1

我是一个新手,在heroku上部署我的应用程序,并像往常一样,它不工作在第一个但是在开发环境中,它工作的很好,我不太了解日志,所以如果有人能够得到帮助,将非常感激。:-)ActionView :: Template :: Error(PG :: Error:错误:操作符不存在:整数=字符变化

这是我的日志

2013-07-04T04:52:28.216823+00:00 app[web.1]:  3:  <%= owned_products_count(@user) %> 
2013-07-04T04:52:28.217058+00:00 app[web.1]: app/views/users/_info.html.erb:14:in `_app_views_users__info_html_erb___312310489209235041_69873501065000' 
2013-07-04T04:52:28.216823+00:00 app[web.1]: ActionView::Template::Error (PG::Error: ERROR: operator does not exist: integer = character varying 
2013-07-04T04:52:28.216823+00:00 app[web.1]: HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts. 
2013-07-04T04:52:28.217058+00:00 app[web.1]: app/views/users/show.html.erb:3:in `_app_views_users_show_html_erb___2418451874712966399_69873501046980' 
2013-07-04T04:52:28.216823+00:00 app[web.1]: LINE 1: ... "products" INNER JOIN "loans" ON "products"."id" = "loans".... 
2013-07-04T04:52:28.216823+00:00 app[web.1]:  5:  <li id="borrowed_products_count"> 
2013-07-04T04:52:28.217058+00:00 app[web.1]: 
2013-07-04T04:52:28.216823+00:00 app[web.1]:               ^
2013-07-04T04:52:28.216823+00:00 app[web.1]:  6:  <b><%= t('product.borrowed.count', count: @user.borrowed_products.count) %></b> 
2013-07-04T04:52:28.217247+00:00 app[web.1]: HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts. 
2013-07-04T04:52:28.216823+00:00 app[web.1]: : SELECT COUNT(*) FROM "products" INNER JOIN "loans" ON "products"."id" = "loans"."product_id" WHERE "loans"."seeker_id" = $1 AND "loans"."current" = 't' AND "loans"."agreed" = 't'): 
2013-07-04T04:52:28.217058+00:00 app[web.1]:  7:  </li> 
2013-07-04T04:52:28.217058+00:00 app[web.1]:  8:  </br> 
2013-07-04T04:52:28.216823+00:00 app[web.1]:  4:  </li> 
2013-07-04T04:52:28.217058+00:00 app[web.1]:  9:  <li id="wanted_products_count"> 
2013-07-04T04:52:28.217058+00:00 app[web.1]: 
2013-07-04T04:52:28.217058+00:00 app[web.1]: app/views/users/_info_products_count.html.erb:6:in `_app_views_users__info_products_count_html_erb__2292303326639587721_69873501081120' 
2013-07-04T04:52:28.217247+00:00 app[web.1]: LINE 1: ... "products" INNER JOIN "loans" ON "products"."id" = "loans".... 
2013-07-04T04:52:28.217247+00:00 app[web.1]:  4:  </li> 
2013-07-04T04:52:28.217058+00:00 app[web.1]: 
2013-07-04T04:52:28.217247+00:00 app[web.1]:  3:  <%= owned_products_count(@user) %> 
2013-07-04T04:52:28.217058+00:00 app[web.1]: ActionView::Template::Error (PG::Error: ERROR: operator does not exist: integer = character varying 
2013-07-04T04:52:28.217247+00:00 app[web.1]:               ^
2013-07-04T04:52:28.217247+00:00 app[web.1]:  5:  <li id="borrowed_products_count"> 
2013-07-04T04:52:28.217247+00:00 app[web.1]:  6:  <b><%= t('product.borrowed.count', count: @user.borrowed_products.count) %></b> 
2013-07-04T04:52:28.217247+00:00 app[web.1]: : SELECT COUNT(*) FROM "products" INNER JOIN "loans" ON "products"."id" = "loans"."product_id" WHERE "loans"."seeker_id" = $1 AND "loans"."current" = 't' AND "loans"."agreed" = 't'): 
2013-07-04T04:52:28.217247+00:00 app[web.1]:  8:  </br> 
2013-07-04T04:52:28.217863+00:00 app[web.1]: app/views/users/show.html.erb:3:in `_app_views_users_show_html_erb___2418451874712966399_69873501046980' 
2013-07-04T04:52:28.217863+00:00 app[web.1]: 
2013-07-04T04:52:28.217863+00:00 app[web.1]: app/views/users/_info.html.erb:14:in `_app_views_users__info_html_erb___312310489209235041_69873501065000' 
2013-07-04T04:52:28.217247+00:00 app[web.1]:  7:  </li> 
2013-07-04T04:52:28.217863+00:00 app[web.1]: app/views/users/_info_products_count.html.erb:6:in `_app_views_users__info_products_count_html_erb__2292303326639587721_69873501081120' 
2013-07-04T04:52:28.217863+00:00 app[web.1]:  9:  <li id="wanted_products_count"> 
2013-07-04T04:52:28.217863+00:00 app[web.1]: 
2013-07-04T04:52:28.209972+00:00 heroku[router]: at=info method=GET path=/users/1 host=letroquet.herokuapp.com fwd="88.138.232.224" dyno=web.1 connect=4ms service=531ms status=500 bytes=1266 

我知道有一些问题,以下文件:

应用/视图/用户/ show.html.erb

<% provide(:title, @user.name) %> 
<aside class="span3"> 
    <%= render 'users/info' %> 
</aside> 
<section class="span9"> 
    <ul class="nav nav-tabs" id="dashboard_products"> 
    <li class="active"><a href="#sharable_products" data-toggle="tab"><%= t('tab.user.show.sharable')%></a></li> 
    <li><a href="#givable_products" data-toggle="tab"><%= t('tab.user.show.givable')%></a></li> 
    </ul> 
    <div class="tab-content"> 
    <%= render 'users/show/sharable_products_list' %> 
    <%= render 'users/show/givable_products_list' %> 
    </div> 
</section> 

应用/视图/用户/ _info.html.erb

<section> 
    <div> 
    <span class="gravatar"> 
     <a href="<%= user_path(@user) %>", title="<%= t('my.profile') %>"><%= gravatar_for @user, size: 52 %> 
     </a> 
    </span> 
    <span class="name"> 
     <h1> 
     <%= @user.name %> 
     </h1> 
    </span> 
    </div> 

    <%= render 'users/info_products_count' %> 

    <%= link_to t('product.create.one'), new_product_path, class: "btn btn-primary" unless !current_user?(@user) %> 
</section> 

应用/视图/用户/ _info_products_count.html.erb

<ul class="unstyled"> 
    <li id="owned_products_count"> 
    <%= owned_products_count(@user) %> 
    </li> 
    <li id="borrowed_products_count"> 
    <b><%= t('product.borrowed.count', count: @user.borrowed_products.count) %></b> 
    </li> 
    </br> 
    <li id="wanted_products_count"> 
    <%= wanted_products_count(@user) %> 
    </li> 
    <li id="requested_products_count"> 
    <%= requested_products_count(@user) %> 
    </li> 
    </br> 
    <li id="given_products_count"> 
    <b><%= t('product.given.count', count: @user.given_products.count) %></b> 
    </li> 
    <li id="returned_products_count"> 
    <b><%= t('product.returned.count', count: @user.returned_products.count) %></b> 
    </li> 
</ul> 

种在这里,我对产品的助手方法:

module ProductsHelper 
    def owned_products_count(user) 
    content_tag(:b, t('product.owned.count', count: user.owned_products.count)) + 
    content_tag(:ul, 
    content_tag(:li, t('product.givable.count', count: user.givable_products.count)) + 
    content_tag(:li, t('product.sharable.count', count: user.sharable_products.count)) 
    ) 
    end 

    def wanted_products_count(user) 
    content_tag(:b, t('product.wanted.count', count: user.wanted_products.count)) + 
    content_tag(:ul, 
    content_tag(:li, t('product.wanted.agreed.count', count: user.agreed_takings.count)) + 
    content_tag(:li, t('product.wanted.refused.count', count: user.refused_takings.count)) 
    ) 
    end 

    def requested_products_count(user) 
    content_tag(:b, t('product.requested.count', count: user.requested_products.count)) + 
    content_tag(:ul, 
    content_tag(:li, t('product.requested.agreed.count', count: user.agreed_borrowings.count)) + 
    content_tag(:li, t('product.requested.refused.count', count: user.refused_borrowings.count)) 
    ) 
    end 
end 

还有我DB/schema.rb

ActiveRecord::Schema.define(version: 20130621065539) do 

    create_table "loans", force: true do |t| 
    t.string "product_id" 
    t.string "seeker_id" 
    t.datetime "borrowing_date" 
    t.datetime "return_date" 
    t.boolean "current" 
    t.boolean "agreed" 
    t.datetime "created_at" 
    t.datetime "updated_at" 
    end 

    add_index "loans", ["product_id", "seeker_id", "borrowing_date", "return_date", "current", "agreed", "created_at"], name: "loans_index" 
    add_index "loans", ["product_id", "seeker_id", "created_at"], name: "index_loans_on_product_id_and_seeker_id_and_created_at", unique: true 

    create_table "ownerships", force: true do |t| 
    t.integer "product_id" 
    t.integer "offerer_id" 
    t.datetime "owning_date" 
    t.datetime "giving_date" 
    t.boolean "current" 
    t.boolean "agreed" 
    t.datetime "created_at" 
    t.datetime "updated_at" 
    end 

    add_index "ownerships", ["product_id", "offerer_id", "created_at"], name: "index_ownerships_on_product_id_and_offerer_id_and_created_at", unique: true 
    add_index "ownerships", ["product_id", "offerer_id", "owning_date", "giving_date", "current", "agreed", "created_at"], name: "ownerships_index" 

    create_table "products", force: true do |t| 
    t.string "name" 
    t.boolean "sharable" 
    t.boolean "givable" 
    t.string "picture_file_name" 
    t.string "picture_content_type" 
    t.integer "picture_file_size" 
    t.datetime "picture_updated_at" 
    t.datetime "created_at" 
    t.datetime "updated_at" 
    end 

    add_index "users", ["email"], name: "index_users_on_email", unique: true 
    add_index "users", ["remember_token"], name: "index_users_on_remember_token" 

end 
+0

可能是你的字段被定义为varchar。 尝试将其更改为整数。 – Rinku

+0

你指的是什么领域? –

+0

我不知道你的模式,但通过错误我可以建议它可能是产品的ID ..你可以分享你的模式? – Rinku

回答

6

在乌尔贷款模式u有product_id字符串。将其改为整数。 很高兴它的工作。 :)

+0

..这里是如何http://stackoverflow.com/questions/3537064/rails-migration-to-convert-string-to-integer – Evolve

相关问题