bwatson30 bwatson30 - 1 year ago 58
Ruby Question

Ruby Rails my link won't work on heroku

I've been trying to deal with this to no avail. It's driving me nuts. Usually, I can sleep on something like this and realize it was a typo in the morning. But I can't sleep until I figure this out - catch 22. Anyway, I have an index of questions being displayed, the title of each question is a link to itself. Nothing surprising there. And it works on local host. When I deploy to heroku, it shows that it's leading me to the correct link and I have it routed correctly when I hover the links. (ie, I definitely have the links set to question_path(question) in the block. yet, when I click the link, it takes me to the questions_path, right back to the index of questions. It's driving me mad. Anyone have a problem like this before?

index.html.erb View:

<% if @quests.present? %>
<% @quests.each do |question| %>
<div class="booyah-box col-xs-10 col-xs-offset-1">
<%= link_to question.qtitle.html_safe, question_path(question) %>
<br />
<bpauthor> A question by <%= question.user.firstname %> <%= question.user.lastname %>, from
<%= %></bpauthor>
<br />
<%= question.qbody.split[0..10].join(" ").html_safe %>... <br /><br />
Answers: <%= question.answers.count %><br />
<% end %>
<% else %>
<p>There are no posts containing the term(s) <%= params[:search] %>.</p>
<% end %>


def index
if params[:search] != nil
@quests =[:search]).order("created_at DESC")
@quests = Question.all.order('created_at DESC')

def show
@question = Question.find(params[:id])
@answer =
@faveanswer =
@ans = Answer.find(params[:id])
@qids = []
@qaids = []
Favanswer.all.each do |favanswer|

@qids << favanswer.question_id
@qaids << [favanswer.question_id, favanswer.answer_id]


Question model:

class Question < ActiveRecord::Base
include Bootsy::Container

mount_uploader :bootsy, BootsyUploader

belongs_to :user
has_many :answers
has_one :favanswer

where("qtitle LIKE ? OR qbody LIKE ?", "%#{search}%", "%#{search}%")

Please tell me I have a typo. I will kiss your feet if you help. I need sleep.

Editing with my heroku logs per Andrew's comment below:

2016-08-01T13:54:20.800626+00:00 app[web.1]: Started GET "/questions/3" for at 2016-08-01 13:54:20 +0000
2016-08-01T13:54:20.803208+00:00 app[web.1]: Processing by QuestionsController#show as HTML
2016-08-01T13:54:20.803238+00:00 app[web.1]: Parameters: {"id"=>"3"}
2016-08-01T13:54:20.806102+00:00 app[web.1]: User Load (1.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT 1 [["id", 1]]
2016-08-01T13:54:20.809813+00:00 app[web.1]: Question Load (0.8ms) SELECT "questions".* FROM "questions" WHERE "questions"."id" = $1 LIMIT 1 [["id", 3]]
2016-08-01T13:54:20.833346+00:00 app[web.1]: Redirected to

Answer Source

Depending on your Heroku configuration, you can either face a 404 error or being redirected (to home by default if I remember well) when the page you're looking for does not exist (either the routing is bad or your controller raises a ActiveRecordNotFound error). If it works in localhost, I would rather explore my second guess. You should check your question object that you are passing to your url helper. Is it correct ? Does it have an id ?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download