English 中文(简体)
我为什么在试图从不同的铁路模型3.1中获取一个模型物体时遇到错误?
原标题:Why do I get an error when trying to access a model object from a different model in Rails 3.1?

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)
最佳回答
问题回答

暂无回答




相关问题
rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

SSL slowness in EC2

We ve deployed our rails app to EC2. In our setup, we have two proxies on small instances behind round-robin DNS. These run nginx load balancers for a dynamically growing and shrinking farm of web ...

Auth-code with A-Za-z0-9 to use in an URL parameter

As part of a web application I need an auth-code to pass as a URL parameter. I am currently using (in Rails) : Digest::SHA1.hexdigest((object_id + rand(255)).to_s) Which provides long strings like : ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

activerecord has_many :through find with one sql call

I have a these 3 models: class User < ActiveRecord::Base has_many :permissions, :dependent => :destroy has_many :roles, :through => :permissions end class Permission < ActiveRecord::...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签