Reputation: 171
So this function actually work on localhost but I am having problem with heroku. What happens is that a user clicks on a user's listings, clicks apply and than an email is send to the listing user. This works on localhost but when I click on submit in heroku I get an error. I looked and found online that it was often connected to a where clause, but I don't think I have a where clause?
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>
and here are my heroku logs
←[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"=>"[email protected]", "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
Please let me know if you need more information and if you need to see the full heroku logs(this is only part of it where the error shows).
Thanks
Upvotes: 1
Views: 1498
Reputation: 351
you incorrectly use find_by method, change:
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
read more http://apidock.com/rails/v4.0.2/ActiveRecord/FinderMethods/find_by
Upvotes: 4