I am in my users/show.html.erb
view, and I am doing this:
<div class="feedback_field span7">
<%= form_for(@feedback) do |f| %>
<div class="poster_id">
<%= f.hidden_field "poster_id", :value => current_user.id %><br />
</div>
<div class="receiver_id">
<%= f.hidden_field "receiver_id", :value => @user.id %><br />
</div>
<div class="field">
<%= f.text_area :content, nil, :maxlength => 250, :class => xxlarge %>
</div>
<%= submit_tag "Send", :class => "btn" %>
<% end %>
</div>
然而,我所看到的错误是:
undefined method `model_name for NilClass:Class
任何想法?
Edit 1
当我增加<条码>@feedback = Feedback.new,以显示我的控制者的行动时,我发现一个rou错,即:
ActionView::Template::Error (No route matches {:controller=>"feedbacks", :format=>nil}):
7: <strong>Share what you think</strong>
8: </div>
9: <div class="feedback_field span7">
10: <%= form_for(@feedback) do |f| %>
11: <div class="poster_id">
12: <%= f.hidden_field "poster_id", :value => current_user.id %><br />
13: </div>
app/views/users/show.html.erb:10:in `_app_views_users_show_html_erb__3843741595115817595_2495618900
app/controllers/vanities_controller.rb:14:in `show
www.un.org/Depts/DGACM/index_spanish.htm Edit 2
我尝试增加<代码>:url备选办法,如:<%=_for(@feedback, :url =>new_feedback_path(@feback)) ;
,并抄:
ActionView::Template::Error (No route matches {:action=>"new", :controller=>"feedbacks"}):
7: <strong>Share what you think</strong>
8: </div>
9: <div class="feedback_field span7">
10: <%= form_for(@feedback, :url => new_feedback_path(@feedback)) do |f| %>
11: <div class="poster_id">
12: <%= f.hidden_field "poster_id", :value => current_user.id %><br />
13: </div>
app/views/users/show.html.erb:10:in `_app_views_users_show_html_erb__3843741595115817595_2166988680
app/controllers/vanities_controller.rb:13:in `show
<><>Edit 3
<>条码>铁路线条码>的相关产出:
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"}
www.un.org/Depts/DGACM/index_spanish.htm Edit 4
对应<代码>feedback资源的道路文件:
scope ":username" do
resources :feedbacks
end
www.un.org/Depts/DGACM/index_spanish.htm Edit 5
这就是<代码>Post行动在我使用root_path
后在form_for
:
Started POST "/" for 127.0.0.1 at 2011-10-17 04:19:27 -0500
Processing by WelcomeController#index as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"0bbhasidfasdf72k2323424=", "feedback"=>{"poster_id"=>"4", "receiver_id"=>"5", "content"=>"Hrmm...this isn t working. How annoying."}, "commit"=>"Send"}
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 4]]
Rendered welcome/index.html.erb within layouts/application (103.5ms)
Completed 200 OK in 118ms (Views: 115.2ms | ActiveRecord: 1.1ms)