2016-08-01 5 views
1

저는 이것을 아무 소용이없는 것으로 처리하려고 노력해 왔습니다. 그것은 나를 미치게합니다. 보통, 나는 이런 식으로 잠을 자고 아침에 오타가 있음을 깨닫습니다. 그러나 나는 이것을 알아낼 때까지 잠을 자지 못한다. 어쨌든 나는 질문의 색인을 가지고있다. 각 질문의 제목은 그 자체에 대한 링크이다. 거기에 놀라운 일이 없습니다. 그리고 그것은 로컬 호스트에서 작동합니다. heroku에 배포 할 때 올바른 링크로 안내한다는 것을 알 수 있으며 링크를 가리면 정확하게 라우팅됩니다. (즉, myapp.herokuapp.com/questions/2). 나는 확실히 블록에 question_path (question)로 설정된 링크를 가지고있다. 그러나 링크를 클릭하면 questions_path로 이동하고 질문 목록으로 돌아갑니다. 나를 미치게 만들었다. 누구나 전에 이런 문제가 있습니까?Ruby Rails 내 링크가 heroku에서 작동하지 않습니다

index.html.erb보기 :

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

questions_controller :

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

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

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

end 
end 

질문 모델 :

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

mount_uploader :bootsy, BootsyUploader 

belongs_to :user 
has_many :answers 
has_one :favanswer 

def self.search(search) 
    where("qtitle LIKE ? OR qbody LIKE ?", "%#{search}%", "%#{search}%") 
end 
end 

오타가 있다고 말해주십시오. 내가 도와 준다면 나는 너의 발에 입맞춤을 할 것이다. 나는 잠이 필요해. 아래 앤드류의 코멘트 당 내 Heroku가 로그와

편집 :

2016-08-01T13:54:20.800626+00:00 app[web.1]: Started GET "https://stackoverflow.com/questions/3" for  162.244.49.116 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  http://mypretendapp.herokuapp.com/questions 
+1

당신의 기록은 영웅에서 무엇이라고 말합니까? 인덱스 메서드로 리디렉션하는 방법에 대한 모든 메모? 'rescue_from' 메소드는 어떨까요? 영웅에 대한 잘못된 데이터로 인해 찾을 수 없기 때문에 무언가가 리디렉션 될 수 있습니까? – Andrew

+0

누군가 대답 할 수 있습니까? 나는 그것에 너무 붙어있다. 루프가 있습니다. 그리고 <% = link_to service.website, service.website, : target => '_blank', rel : "nofollow"%> 작동하지 않습니다. –

답변

1

당신의 Heroku 구성에 따라, 찾고있는 페이지가 존재하지 않을 때 404 오류가 발생하거나 (기억이 잘 나는 경우 기본적으로 집으로) 리디렉션 될 수 있습니다 (라우팅이 잘못되었거나 컨트롤러 ActiveRecordNotFound 오류가 발생합니다. localhost에서 작동하는 경우 두 번째 추측을 탐구합니다. question 개체를 확인하여 URL 도우미로 전달해야합니다. 맞습니까? 이드가 있니?

+0

나는 이것도 생각하지 않는다. 질문 객체는 맞습니다. 링크를 가리키면 나타나는 링크와 위에서 추가 한 영웅 로그에 의해 확인됩니다. 경로는 이것을 보여줍니다.'question GET /questions/:id(.:format) questions # show' – bwatson30

+0

show 디버거를 사용하여 show 메소드에서 vars를 검사 했습니까? 모든 변수가 괜찮습니까? 특히'@ question'과'@ ans'는'find'를 사용합니다. – Aeradriel

+0

* smooch * 많은, 많은, 많은 mahalos 내 친구. 나는 다른 곳에서 보지 않은 질문 변수에 너무 집중했다. 위대한 부름 - 그것은 무의미한 @ans 변수였습니다. 나는 그것이 어떻게 거기에서 끝났는지, 또는 내가 왜 그것을 가지고 있었는지를 모른다. 그러나 'ActiveRecordNotFound' 오류가 발생했습니다. 바라건대,이 스레드는 언젠가 다른 사람에게 유용 할 것입니다! – bwatson30

0

당신은 @question

<%= link_to question.qtitle.html_safe, question_path(question) %> 

에서 변수 question를 교체 시도? 내가 올바르게 읽는다면 @question 대신 do 루프 때문에 @quests으로 되돌아 갈 것입니다.

+0

그건 그렇지 않아. '@ quests'는 모든 질문을 의미하므로 블록은'@quests.each'를 참조하므로'@ quests'에있는 각 객체에 대해 (질문이)이 작업을 수행하고 각 객체를 "질문"을 반복하십시오. '@ question'은 색인마다 존재하지 않습니다. '@quests'는'@ question' 이었지만, 이렇게 블록에서 혼란스러워지기 시작했습니다. – bwatson30

관련 문제