귀하의 TransactionsController#index
작업이 @transactions에 대해 아무것도 반환하지 않는 것으로 보입니다. 가장 명백한 원인은 레코드를 찾기 위해 사용하는 논리가 잘못되어 0 개의 결과를 반환하거나 @transactions를 올바르게 설정하지 않는다는 것입니다.
그런보기에서 결과가없는 상황 (또는 일종의 오류)에 대해 오류 검사를 수행하려고합니다.
귀하의 index.html을보기 : 부분
<% if [email protected] || @transactions.length == 0 %>
<p>'No transactions found.'</p>
<% else %>
<table>
<!-- put your column headers here -->
<!-- the next line iterates through each transaction and calls a "_transaction" partial to render the content -->
<%= render @transactions %>
</table>
<% end %>
귀하의 _transaction.html.erb :보기가 다시 작동됩니다
<tr>
<td><%= transaction.transaction_type %></td>
<td><%= transaction.date %></td>
</tr>
. 다음 단계는 컨트롤러 동작이 결과를 반환하지 않는 이유를 파악하는 것입니다. 레일 콘솔을 열고 레코드를 검색하여 시작하십시오.
>> Transaction.all
결과가 반환되면 데이터가 반환됩니다. 그렇지 않다면, 당신이 개발 한 웹 인터페이스를 통해 또는 레일 콘솔을 통해 중 하나 레코드를 작성 : 당신이 기록이되면
>> t = Transaction.new()
>> t.transaction_type = 1 #or whatever is appropriate for your application
>> t.date = Date.today
>> t.valid? #if true, your record will save. If not, you need to fix the fields so they validate
>> t.save
가 다시보기를 테스트합니다. 그래도 실패하면 컨트롤러 로직에 오류가있을 것입니다. 그 오류가 무엇인지에 관해서는, 우리가 당신을 도와주기 위해 게시해야합니다. :)
@transactions 변수가 전혀 설정되어 있지 않은 것으로 보입니다. 컨트롤러에 설정 하시겠습니까? 어쩌면 @ 전에 이름을 잊어 버렸을까요? – tomeduarte