<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>akawa (akawa)</title>
    <link>https://ruby-china.org/akawa</link>
    <description></description>
    <language>en-us</language>
    <item>
      <title>关于 form_for,新手绊门槛上了……</title>
      <description>&lt;p&gt;ROR 新手，以前是做前端的
久仰 rais 大名于是决定自学
跟着 Ruby on Rails Tutorial 过了一遍 rails 后决定自己动手试试
index,show 等 GET 页面都没事
结果到 new 这个 POST 页面就被卡住了，已经卡了一天了有没有……
看不明白为啥总说我路径错误，如果我用脚手架生产一套 controller 和 model 的话，把生成的数据表名换到这里倒是可用
不过这也不是解决办法……&lt;/p&gt;

&lt;p&gt;求老鸟，大牛带一程……谢了&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;NoMethodError in User#new

Showing /home/vilppu/projects/demo/app/views/user/new.html.erb where line #1 raised:

undefined method `users_path' for #&amp;lt;#&amp;lt;Class:0xb2f3b468&amp;gt;:0xb3013e80&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;hr&gt;

&lt;p&gt;&lt;strong&gt;routes.rb&lt;/strong&gt;&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;root to: "user#index"
resources :user
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;new.html.erb&lt;/strong&gt;&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;%= form_for(@user) do |f| %&amp;gt;
    &amp;lt;%= f.label :name %&amp;gt;
    &amp;lt;%= f.text_field :name %&amp;gt;

    &amp;lt;%= f.label :age %&amp;gt;
    &amp;lt;%= f.text_field :age %&amp;gt;

    &amp;lt;%= f.submit 'submit' %&amp;gt;
&amp;lt;% end %&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;user_controller.rb&lt;/strong&gt;&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class UserController &amp;lt; ApplicationController
  def index
    @users = User.all
  end

  def show
    @user = User.find(params[:id])
  end

  def new
    @user = User.new
  end

end

&lt;/code&gt;&lt;/pre&gt;</description>
      <author>akawa</author>
      <pubDate>Fri, 01 Feb 2013 21:20:32 +0800</pubDate>
      <link>https://ruby-china.org/topics/8557</link>
      <guid>https://ruby-china.org/topics/8557</guid>
    </item>
  </channel>
</rss>
