我对 Rails 知之甚少,我继承了这个项目。在过去的几天里,我一直在尝试了解“link_to”和“routes.rb”。这些东西让我发疯 - 我花了一整天的时间看着它,将一些代码粘贴到裸项目中,它可以在哪里工作......但我只是不明白我在这里遇到的错误,或者如何去关于解决它,所以如果你有任何想法......
在我的页面 _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
无论如何,如果您有任何想法可能出了什么问题,我很高兴知道....谢谢。
克里斯托夫。