我創建使用Rails 3.2.5
一個博客,並利用途徑產生的(即我code_entries
:code_entries_path
,new_code_entry_path
等)中的資源路徑已經使用link_to
的每一個動作整個網站。突然每當我試圖訪問一個頁面我得到這個錯誤:路線生成的路徑已經停止工作
undefined local variable or method `controller' for #<CodeEntriesController:0x007f887f8b3300>
此錯誤是從我index
行動我code_entries_controller.rb
,但無論哪個動作我嘗試去到任何控制器我得到這個帶有路由資源路徑的每個link_to
錯誤。它之前工作正常,我不確定會造成這種情況。
由於這個問題是我code_entries
的情況下,這裏是code_entries_controller.rb
,/code_entries/index.html.haml
,routes.rb
代碼,我已經得到了錯誤,但在行動code_entries#index
的背景:
code_entries_controller.rb
class CodeEntriesController < ApplicationController
before_filter :authenticate_action
def index
@entries = CodeEntry.order("created_at desc")
end
def new
@entry = CodeEntry.new
end
def show
@entry = CodeEntry.find_by_id(params[:id])
end
def create
@entry = CodeEntry.new(params[:code_entry])
if @entry.save
redirect_to code_entry_path(@entry), :notice => "#{@entry.title} has been created"
else
puts @entry.errors.messages.inspect
render "new"
end
end
def edit
@entry = CodeEntry.find_by_id(params[:id])
end
def update
@entry = CodeEntry.find_by_id(params[:id])
if @entry.update_attributes(params[:code_entry])
redirect_to code_entry_path(@entry), :notice => "#{@entry.title} has been updated"
else
puts @entry.errors.messages.inspect
render "edit"
end
end
def destroy
@entry = CodeEntry.find_by_id(params[:id])
@entry.destroy
redirect_to code_entries_path, :notice => "#{@entry.title} has been deleted"
end
end
/code_entries/index.html.haml
%h1 Hello!
%br
- @entries.each do |e|
%h2= link_to e.title, code_entry_path(e)
%h3= e.updated_at
= raw excerpt(e, 200)
%br
- if current_user
= link_to "Edit", edit_code_entry_path(e)
= button_to "Delete", code_entry_path(e), :confirm => "Really really?", :method => :delete
%hr
routes.rb
Blog::Application.routes.draw do
resources :users
resources :code_entries
resources :food_entries
resources :inclusive_entries
resources :sessions
root :to => "home#index"
get "login" => "sessions#new", :as => "login"
get "logout" => "sessions#destroy", :as => "logout"
get "users/new"
end
NameError in Code_entries#index
顯示/Users/kyle/Projects/blog/app/views/code_entries/index.html。HAML其中線#4提出:
undefined local variable or method `controller' for #<CodeEntriesController:0x007f887f813418>
提取的源(圍繞線#4):
1: %h1 Hello!
2: %br
3: - @entries.each do |e|
4: %h2= link_to e.title, code_entry_path(e)
5: %h3= e.updated_at
6: = raw excerpt(e, 200)
7: %br
Rails.root: /Users/kyle/Projects/blog
應用程序跟蹤|框架跟蹤|全面跟蹤
app/views/code_entries/index.html.haml:4:in `block in _app_views_code_entries_index_html_haml___3334012984247114074_70112115764360'
app/views/code_entries/index.html.haml:3:in `_app_views_code_entries_index_html_haml___3334012984247114074_70112115764360'
Request
參數:
None
顯示會話轉儲
顯示ENV轉儲
響應
頁眉:
None