2012-08-13 69 views
-1
  1. 創建一個名爲User的新控制器。爲它創建以下頁面 它:索引,註冊,登錄和註銷。這足以使用 生成器腳本來實現這一點。如何將新項目添加到主菜單中?

  2. 添加新項目到主菜單:註冊和登錄。主菜單 在應用程序佈局文件 app \ views \ layouts \ application.html.erb中定義。請注意,我們尚未在此階段向索引頁面添加菜單鏈接 。

  3. 試用您的應用程序。如果新頁面不起作用,請重新啓動 Mongrel Web應用程序。

第二點是什麼?我應該怎麼做?

+1

請重新解釋您的問題並解釋您所做的事情,您嘗試實現的目標以及您遇到的困難。我還建議提供一些代碼來支持你的問題,所以我們有一些工作。 – jstr 2012-08-13 09:23:11

+0

我在(http://rails.francik.name/tutorial/chapter/5)中看到了一個例子,並且如上例所示,我創建了一個控制器用戶,當你可以看到第二個點時,將新項目添加到主菜單中。我不知道我該怎麼做。 – 2012-08-13 09:28:18

+0

你需要提供更多的細節。我建議對你的問題進行重新說明,並且包括一些與你被卡住的教程部分相關的代碼。如果沒有更多的信息/更好的描述,幾乎不可能解釋你的問題。 – jstr 2012-08-13 09:30:44

回答

0

亞雷克Francik是我的老師在金斯頓大學...

我沒有這個教程幾年前。第二步是添加鏈接爲您生成新的動作:index, register, login and logout

轉到您的application.html.erb並對其進行編輯:

... 
    <div id="nav"> 
    <%= link_to_unless_current "Home", :controller => "site", 
             :action => "index" %> | 
    <%= link_to_unless_current "About", :controller => "site", 
             :action => "about" %> | 
    <%= link_to_unless_current "Help", :controller => "site", 
             :action => "help" %> | 

    #include the new actions as the example below: 
    <%= link_to_unless_current "Login", :controller => "user", 
             :action => "login" %> | 

</div> 

另外請注意,本教程是爲Rails 2.3。 9。我建議你把他約軌3和購物車視頻一看:http://ecommerce2011.tumblr.com/post/11687504985/lecture-4-techniques-part-2-the-shop-on-rails

0

在​​,第9(收尾),創建下面的代碼片段導航菜單:

<div id="nav"> 
    <%= link_to_unless_current "Home", :controller => "site", 
             :action => "index" %> | 
    <%= link_to_unless_current "About", :controller => "site", 
             :action => "about" %> | 
    <%= link_to_unless_current "Help", :controller => "site", 
             :action => "help" %> 
</div> 

要將新項目添加到菜單中,您需要在導航div中再創建兩個link_to_unless_current調用。例如,更改後的代碼可能如下所示:

<div id="nav"> 
    <%= link_to_unless_current "Home",  :controller => "site", 
             :action => "index" %> | 
    <%= link_to_unless_current "About", :controller => "site", 
             :action => "about" %> | 
    <%= link_to_unless_current "Help",  :controller => "site", 
             :action => "help" %> | 
    <%= link_to_unless_current "Register", :controller => "user", 
             :action => "register" %> | 
    <%= link_to_unless_current "Login", :controller => "user", 
             :action => "login" %> 
</div> 

我建議回到第3章並檢查您是否瞭解發生了什麼。

相關問題