2016-07-24 97 views
0

所以我想提出一個顏色調色板經理,並要求在表格上兩個表嵌套和正確關聯(我想也指出,我是菜鳥到軌)軌不能創建一個對象

這整個代碼是工作完全正常時,在第4行中請求鏈接,而不是僅僅是名字,突然不會再工作,感謝你的幫助提前

<div class='nav_bar'>#</div> 
    <% if @projects %> 
     <% @projects.each do |project| %> 
      <li><div class='container'><h1><%= project.name project_path(:id => project.id) %></h1> 
       <ul> 
        <%= form_for project do %> 
        <%= fields_for :palette, project.palette do |palette| %> 

         <%= palette.label 'background_dark_color' %>: 
         <%= palette.text_field :background_dark_color, placeholder: '@palette.background_dark_color' %><br/> 

         <%= palette.label 'background_light_color' %>: 
         <%= palette.text_field :background_light_color, placeholder: "@palette.background_light_color" %><br/> 

         <%= palette.label 'dark_color1' %>: 
         <%= palette.text_field :dark_color1, placeholder: "@palette.dark_color1" %><br/> 

         <%= palette.label 'dark_color2' %>: 
         <%= palette.text_field :dark_color2, placeholder: "@palette.dark_color2" %><br/> 

         <%= palette.label 'light_color1' %>: 
         <%= palette.text_field :light_color1, placeholder: "@palette.light_color1" %><br/> 

         <%= palette.label 'light_color2' %>: 
         <%= palette.text_field :light_color2, placeholder: "@palette.light_color2" %><br/> 

         <%= palette.submit %> 

         <%= link_to 'Destroy', project, method: :delete, data: { confirm: 'Are you sure?' } %> 

        <% end %> 
        </div> 
       </ul> 

      <% end %></li> 
     <%end%> 
    <%end%> 
    <div class='circle'><%= link_to "+", new_project_path %></div> 
    <button type="button"><%= link_to "+", new_project_path %></button> 

回答

0

我想你指的是以下行,

<%= project.name project_path(:id => project.id) %> 

此代碼存在錯誤。有兩種方法可以解決這個問題。

解決方案1 ​​

如果你想顯示一個鏈接,錨標籤這個用用下面的代碼替換此,

<%= link_to project.name, project_path(:id => project.id) %> 

解決方案2

如果你不不想要鏈接,只需要出現的名稱,請執行以下操作:

<%= project.name %> 
+0

非常感謝你,這實際上解決了我的問題,我確實感到有點愚蠢,因爲我不知道這個問題 –

+0

沒問題,我們都犯錯誤並學習。很高興爲您提供幫助。 – Pragash