Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat are some possible reasons that you would get an undefined method 'TheModelName_path' error using a form_for in rails 3?
    primarykey
    data
    text
    <p>I can't figure out why I have this error from my knowledge everything is set up as it should to work. </p> <p><strong>this is the error i get:</strong> NoMethodError at /short/new undefined method `shorts_path' for #&lt;#:0x007fbc441426e0></p> <ol> <li>my model is short not shortS</li> <li>when I run rake routes there is no <code>shorts_path</code> so I'm not sure where this helper is coming from. I don't understand why the <code>form_for</code> is giving me this error when <code>@short</code> is defined in the <code>def new</code> section of my controller.</li> </ol> <p>Can someone please explain this to me?</p> <p>Thank you in advance </p> <p><strong>This is what my controller looks like</strong></p> <pre><code>class ShortController &lt; ApplicationController def show @short = Short.find(params[:id].to_i(36)) respond_to do |format| #redirect directly to the url stored as long in the database format.html { redirect_to @short.long} end end def new @short = Short.new respond_to do |format| format.html # new.html.erb end end def create @short = Short.new(params[:short]) respond_to do |format| if @short.save format.html { render action: "show" } else format.html { render action: "new" } end end end end </code></pre> <p><strong>routes</strong></p> <pre><code>Trainingproject::Application.routes.draw do root :to =&gt; 'short#welcome' resources :short, :only =&gt; [:new, :create, :show] end </code></pre> <p><strong>form partial which is rendered in the view for new</strong></p> <pre><code>&lt;%= form_for(@short) do |f| %&gt; &lt;% if @short.errors.any? %&gt; &lt;div id="error_explanation"&gt; &lt;h2&gt;&lt;%= pluralize(@short.errors.count,"error") %&gt; prohibited this url from being saved:&lt;/h2&gt; &lt;ul&gt; &lt;% @short.errors.full_messages.each do |msg| %&gt; &lt;li&gt;&lt;%= msg %&gt;&lt;/li&gt; &lt;% end %&gt; &lt;/ul&gt; &lt;/div&gt; &lt;% end %&gt; &lt;div class="form-field"&gt; &lt;%= f.label "Enter your URL" %&gt;&lt;br /&gt; &lt;%= f.text_field :long %&gt; &lt;/div&gt; &lt;div class="actions"&gt; &lt;%= f.submit %&gt; &lt;/div&gt; &lt;% end %&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload