错误:错误:WHERE的参数必须是boolean类型,而不是类型integer

时间:2014-08-27 23:20:01

标签: ruby-on-rails ruby heroku

所以这个函数实际上可以在localhost上运行但是我遇到了heroku的问题。 发生的情况是,用户点击用户的列表,点击应用,然后将电子邮件发送给列表用户。这适用于localhost但是当我在heroku中单击提交时,我收到错误。 我在线查看并发现它经常连接到where子句,但我认为我没有where子句?

listings_controller.rb

def send_resume_email
        @listing = Listing.find_by(params[:id])
        @user = User.find_by(params[:id])
        UserMailer.new_resume(@user, @listing).deliver
        redirect_to findjobs_path, notice: 'Message sent'
    end

user_mailer.rb

 def new_resume(user, listing)
    @listing = listing
    @user = user
    @url = 'http://www.example.com'
    mail(to: listing.user.email, subject: 'Thanks for the awesome site')
end

apply.html.erb

<div class="top">
<div class="container-content">
    <div class="container">
        <%= form_tag(listing_send_resume_email_path) do %>
            <div class="form-group">
                <%= label_tag 'name', 'Name' %>
                <%= text_field_tag 'name', nil, class: 'form-control', placeholder: 'Your Name' %>
            </div>
           <div class="form-group">
               <%= label_tag 'email', 'Email' %>
               <%= email_field_tag 'email', nil, class: 'form-control', placeholder: 'Your Email Address' %>
           </div>
           <div class="form-group">
               <%= label_tag 'comments', 'Comments' %>
               <%= text_area_tag 'comments', nil, class: 'form-control', rows: 4, placeholder: 'Comments...' %>
           </div>
           <%= submit_tag nil, class: 'btn btn-default btn-about pull-right' %>
       <% end %>
  </div>
</div>
</div>

这是我的heroku日志

←[33m2014-08-27T22:41:16.216199+00:00 heroku[router]:←[0m at=info method=POST pa
th="/4/apply/send_resume_email" host=nightjobs.herokuapp.com request_id=6cc269c8
-05ed-47a8-8718-32e5153f4b70 fwd="130.212.122.85" dyno=web.1 connect=1ms service
=14ms status=500 bytes=1408
←[36m2014-08-27T22:41:16.206040+00:00 app[web.1]:←[0m Started POST "/4/apply/sen
d_resume_email" for 130.212.122.85 at 2014-08-27 22:41:16 +0000
←[36m2014-08-27T22:41:16.213858+00:00 app[web.1]:←[0m
←[36m2014-08-27T22:41:16.213860+00:00 app[web.1]:←[0m ActiveRecord::StatementInv
alid (PG::Error: ERROR:  argument of WHERE must be type boolean, not type intege
r
←[36m2014-08-27T22:41:16.213863+00:00 app[web.1]:←[0m LINE 1: SELECT  "listings"
.* FROM "listings"  WHERE (4)  ORDER BY cr...
←[36m2014-08-27T22:41:16.213864+00:00 app[web.1]:←[0m
                           ^
←[36m2014-08-27T22:41:16.213866+00:00 app[web.1]:←[0m : SELECT  "listings".* FRO
M "listings"  WHERE (4)  ORDER BY created_at DESC LIMIT 1):
←[36m2014-08-27T22:41:16.213868+00:00 app[web.1]:←[0m   app/controllers/listings
_controller.rb:26:in `send_resume_email'
←[36m2014-08-27T22:41:16.213869+00:00 app[web.1]:←[0m
2014-08-27T22:41:16.213870+00:00 app[we
b.1]:
←[36m2014-08-27T22:41:16.208813+00:00 app[web.1]:←[0m Processing by ListingsCont
roller#send_resume_email as HTML
←[36m2014-08-27T22:41:16.208859+00:00 app[web.1]:←[0m   Parameters: {"utf8"=>"??
?", "authenticity_token"=>"FvlxqOYrg9lFt0+zsIVBSzW8UXbcazR7LamdmRg3uR0=", "name"
=>"Friederike Geiken", "email"=>"myemail@gmail.com", "comments"=>"asd", "commit
"=>"Submit", "id"=>"4"}
←[36m2014-08-27T22:41:16.212273+00:00 app[web.1]:←[0m PG::Error: ERROR:  argumen
t of WHERE must be type boolean, not type integer
←[36m2014-08-27T22:41:16.212276+00:00 app[web.1]:←[0m LINE 1: SELECT  "listings"
.* FROM "listings"  WHERE (4)  ORDER BY cr...
←[36m2014-08-27T22:41:16.212278+00:00 app[web.1]:←[0m
                           ^
←[36m2014-08-27T22:41:16.212281+00:00 app[web.1]:←[0m : SELECT  "listings".* FRO
M "listings"  WHERE (4)  ORDER BY created_at DESC LIMIT 1
←[36m2014-08-27T22:41:16.212448+00:00 app[web.1]:←[0m Completed 500 Internal Ser
ver Error in 4ms

如果您需要更多信息,并且需要查看完整的heroku日志(这只是错误显示的一部分),请告诉我。

由于

1 个答案:

答案 0 :(得分:4)

您错误地使用了find_by方法,请更改:

  def send_resume_email
    @listing = Listing.find_by(id: params[:id])
    @user = User.find_by(id: params[:id])
    UserMailer.new_resume(@user, @listing).deliver
    redirect_to findjobs_path, notice: 'Message sent'
  end

了解更多http://apidock.com/rails/v4.0.2/ActiveRecord/FinderMethods/find_by