我不太瞭解Rails,我繼承了這個項目。在過去的幾天裏,我一直在努力探索,'link_to'和'routes.rb'。這些東西讓我很生氣 - 我花了整整一天的時間看着它,將代碼粘貼到裸露的項目中,在那裏工作..但我不明白我在這裏得到的錯誤,或者如何去關於解決它,所以如果你有任何想法....Rails link_to靜態頁面問題
在我的網頁_signed_in_header.html.erb我:
<a href="../staticpages/faq">FAQ</a>
在我的routes.rb我:
get "staticpages/faq"
我知道這是設置正確的,因爲當我從頭開始一個示例項目時,它的工作原理。
但我繼承了這個特殊的項目中,我得到的錯誤:
NoMethodError in Staticpages#faq
Showing /home/christophecompaq/Populisto/app/views/layouts/_signed_in_header.html.erb where line #48 raised:
undefined method `model_name' for NilClass:Class
Extracted source (around line #48):
45:
46: <div class='search-box'>
47: <%= simple_form_for @review, :url => search_index_path, :method => :post, :html => { :class => 'form-horizontal'} do |f| %>
48:
49: <%= f.input :search_ids, :collection => @data, :as => :grouped_chosen,
50: :group_method => :last, :prompt => false,
51: :input_html => { :class => 'span5', :multiple => true },
Trace of template inclusion: app/views/layouts/_header.html.erb, app/views/layouts/application.html.erb
Rails.root: /home/christophecompaq/Populisto
Application Trace | Framework Trace | Full Trace
app/views/layouts/_signed_in_header.html.erb:48:in `_app_views_layouts__signed_in_header_html_erb___586079249_69970641688720'
app/views/layouts/_header.html.erb:1:in `_app_views_layouts__header_html_erb__1905506502_69970640142220'
app/views/layouts/application.html.erb:21:in `_app_views_layouts_application_html_erb___1868096314_69970642536740'
編輯:有人問我,以顯示我的檢討控制器代碼,所以這裏有雲:
class ReviewsController < FrontEndController
respond_to :html, :json
before_filter :with_google_maps_api
def index
@review = Review.new
end
def create
@review = Review.create((params[:review] || {}).merge(:user_id => current_user.id))
if @review.save
redirect_to landing_page, :notice => I18n.t('write_review.review_successfully_created')
else
render :action => :index
end
end
def show
@review = Review.find(params[:id])
end
def edit
@review = Review.find(params[:id])
end
def update
@review = Review.find(params[:id])
if @review.update_attributes(params[:review])
else
render :edit
end
end
def destroy
@review = Review.find(params[:id])
@review.destroy
end
def repost
@review = Review.find(params[:id])
@review.repost(current_user)
end
def reject
@review = Review.find(params[:id])
current_user.reject @review
end
end
不管怎麼說,如果你有什麼想法可能是錯誤的,我會很高興知道....謝謝。
Christophe。
在你的路由文件
很可能,模板試圖訪問尚未分配的變量(可能是實例變量)。根據所包含的來源,我可能會猜測「@ review」是有問題的變量。 – 2013-03-20 22:53:50