2016-04-28 86 views
0

我有兩個對象,網站和分數。網站has_many分數和分數belongs_to一個網站。我正在嘗試爲我的分數構建新視圖,以便我可以爲特定網站添加分數。在視圖中調用belongs_to關係

這裏是我的show.html.erb鑑於我的站點對象

<h1> 
    <%= @site.name %> 
    <%= @site.net_promoter_score %> 
    <% @site.scores.each do |score| %> 
     <li> 
      <%= score.value %> 
     </li> 
    <% end %> 
</h1> 
<br> 
<%= link_to "Create Score", new_score_path(site_id: @site.id) %> 
<br> 
<%= link_to "Back to Index", sites_path %> 

這裏是我的得分新觀點:

<html> 
    <body> 
     <h1 style="text-align:center"> 
      @site.name 
     </h1> 
     <br> 

     <h2 style="text-align:center"> 
     On a scale from 1-10, how likely are you to recommend this site to a friend or colleague? 
     </h2> 
     <form id="NPSform"; style= "text-align:center"> 
      <input type="submit" name="mysubmit" value="Submit"/> 
     </form> 
    </body> 
</html> 

<script> 
    var inputs = ''; 
    for (var i = 1; i <= 10; i++) { 
     inputs += '<input name="scores" type="radio" value="' + i + '" id="' + i + '">' + i; 
    } 
    document.getElementById('NPSform').insertAdjacentHTML('afterbegin', inputs); 
</script> 

<%= link_to "Back to Index", sites_path %> 

我怎樣才能確保我引用在我的show view中通過new_score_path傳遞的網站是否正確?

回答