CHa*_*ris 1 ruby-on-rails link-to
我对Rails了解不多,我继承了这个项目.在过去的几天里,我一直在努力探索,"link_to"和"routes.rb".这个东西让我很生气 - 我花了一整天的时间来看待它,把一些代码粘贴到裸露的项目中,它的工作原理......但我只是不明白我到这里的错误,或者怎么去关于解决它,所以如果你有任何想法....
在我的页面_signed_in_header.html.erb我有:
<a href="../staticpages/faq">FAQ</a>
Run Code Online (Sandbox Code Playgroud)
在我的routes.rb我有:
get "staticpages/faq"
Run Code Online (Sandbox Code Playgroud)
我知道这是正确的,因为当我从头开始一个示例项目时,它的工作原理.
但在这个特定的项目中,我继承了我得到的错误:
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'
Run Code Online (Sandbox Code Playgroud)
编辑:我被要求显示我的评论控制器代码,所以在这里:
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
Run Code Online (Sandbox Code Playgroud)
无论如何,如果你有任何想法可能是错的,我会很高兴知道....谢谢.
克里斯托夫.
在您的路径文件中,使用此代码
get "staticpages/faq", :as => 'faq_page'
Run Code Online (Sandbox Code Playgroud)
在"为"将产生2个的辅助功能:faq_page_url和faq_page_path,你可以在你的代码中使用
| 归档时间: |
|
| 查看次数: |
5467 次 |
| 最近记录: |