這是我的路線:如何爲嵌套資源的視圖渲染局部圖像? - Rails的3.1
scope ":username" do
resources :feedbacks
end
我對我home/index.html.erb
看法,我試圖做到這一點:
<%= render "feedbacks/form" %>
但是這給了我這個錯誤:
ActionView::Template::Error (No route matches {:controller=>"feedbacks", :format=>nil}):
1: <%= form_for(@feedback) do |f| %>
2: <% if @feedback.errors.any? %>
3: <div id="error_explanation">
4: <h2><%= pluralize(@feedback.errors.count, "error") %> prohibited this feedback from being saved:</h2>
app/views/feedbacks/_form.html.erb:1:in `_app_views_feedbacks__form_html_erb__3181571289116259961_2487495480'
app/views/home/index.html.erb:18:in `_app_views_home_index_html_erb___397233383548615486_2487321620'
這是我的耙路線反饋意見:
feedbacks GET /:username/feedbacks(.:format) {:action=>"index", :controller=>"feedbacks"}
POST /:username/feedbacks(.:format) {:action=>"create", :controller=>"feedbacks"}
new_feedback GET /:username/feedbacks/new(.:format) {:action=>"new", :controller=>"feedbacks"}
edit_feedback GET /:username/feedbacks/:id/edit(.:format) {:action=>"edit", :controller=>"feedbacks"}
feedback GET /:username/feedbacks/:id(.:format) {:action=>"show", :controller=>"feedbacks"}
PUT /:username/feedbacks/:id(.:format) {:action=>"update", :controller=>"feedbacks"}
DELETE /:username/feedbacks/:id(.:format) {:action=>"destroy", :controller=>"feedbacks"}
編輯1
當我通過在本地實例變量@feedback
這樣的:這是從我的home controller
,在此聲明如下拉:
class HomeController < ApplicationController
def index
@users = User.all
@feedback = Feedback.new
end
end
我仍然得到這個錯誤:
Routing Error
No route matches {:controller=>"feedbacks", :format=>nil}
編輯2
我也有我的路線文件中指定一個users
資源,看起來像這樣:
resources :users
scope ":username" do
resources :feedbacks
end
你可能是對的。這是我從'logger.info'中看到的:'feedback object:#
marcamillion
我更新了問題以反映我嘗試過的其他事情。 – marcamillion
就是這樣,我在動作中(@ home&'feedback'控制器)聲明瞭'@feedback = Feedback.new',因爲我調用了部分的視圖。它仍然給我這個錯誤,即使在我用你的語法。此外,我的語法是正確的:http://guides.rubyonrails.org/layouts_and_rendering.html#using-partials但我仍然嘗試了你的語法,但仍然收到錯誤。 – marcamillion