Note that there are some explanatory texts on larger screens.

plurals
  1. PORails routing error doesn't recognize id
    text
    copied!<p>I have a controller "manage_links.rb" that allows users to manage their links, which have a corresponding "link" model. I am getting the following error:</p> <pre><code>ActionController::RoutingError in Manage_links#index Showing app/views/manage_links/index.html.erb where line #16 raised: edit_manage_link_url failed to generate from {:controller=&gt;"manage_links", :action=&gt;"edit", :id=&gt;nil}, expected: {:controller=&gt;"manage_links", :action=&gt;"edit"}, diff: {:id=&gt;nil} Extracted source (around line #16): 13: &lt;td&gt;&lt;%=h link.text %&gt;&lt;/td&gt; 14: &lt;td&gt;&lt;%=h link.url %&gt;&lt;/td&gt; 15: &lt;td&gt;&lt;%= link_to 'Show', manage_link_path(link.id) %&gt;&lt;/td&gt; 16: &lt;td&gt;&lt;%= link_to 'Edit', edit_manage_link_path(link.id) %&gt;&lt;/td&gt; 17: &lt;td&gt;&lt;%= link_to 'Destroy', manage_link_path(link.id), :confirm =&gt; 'Are you sure?', :method =&gt; :delete %&gt;&lt;/td&gt; 18: &lt;/tr&gt; 19: &lt;% end %&gt; </code></pre> <p>I've got the following line in my config/routes.rb:</p> <blockquote> <p>map.resources :manage_links</p> </blockquote> <p>Here's an excerpt of what I get when I run "rake routes":</p> <blockquote> <pre><code> manage_links GET /manage_links(.:format) POST /manage_links(.:format) new_manage_link GET /manage_links/new(.:format) edit_manage_link GET /manage_links/:id/edit(.:format) manage_link GET /manage_links/:id(.:format) PUT /manage_links/:id(.:format) DELETE /manage_links/:id(.:format) </code></pre> </blockquote> <p>and here's the full code block that's causing the error:</p> <pre><code>&lt;% @links.each do |link| %&gt; &lt;tr&gt; &lt;td&gt;&lt;%=h link.text %&gt;&lt;/td&gt; &lt;td&gt;&lt;%=h link.url %&gt;&lt;/td&gt; &lt;td&gt;&lt;%= link_to 'Show', manage_link_path(link.id) %&gt;&lt;/td&gt; &lt;td&gt;&lt;%= link_to 'Edit', edit_manage_link_path(link.id) %&gt;&lt;/td&gt; &lt;td&gt;&lt;%= link_to 'Destroy', manage_link_path(link.id), :confirm =&gt; 'Are you sure?', :method =&gt; :delete %&gt;&lt;/td&gt; &lt;/tr&gt; &lt;% end %&gt; </code></pre> <p>here is the controller code:</p> <pre><code>class ManageLinksController &lt; ApplicationController before_filter :login_required before_filter :find_user # GET /links # GET /links.xml def index @links = @user.links respond_to do |format| format.html # index.html.erb format.xml { render :xml =&gt; @links } end end # GET /links/1 # GET /links/1.xml def show @link = @user.links.find(params[:id]) respond_to do |format| format.html # show.html.erb format.xml { render :xml =&gt; @link } end end # GET /links/new # GET /links/new.xml def new @link = @user.links.build respond_to do |format| format.html # new.html.erb format.xml { render :xml =&gt; @link } end end # GET /links/1/edit def edit @link = @user.links.find(params[:id]) end # POST /links # POST /links.xml def create @link = @user.links.build(params[:id]) respond_to do |format| if @link.save flash[:notice] = 'Link was successfully created.' format.html { redirect_to manage_link_url(@link) } format.xml { render :xml =&gt; @link, :status =&gt; :created, :location =&gt; @link } else format.html { render :action =&gt; "new" } format.xml { render :xml =&gt; @link.errors, :status =&gt; :unprocessable_entity } end end end # PUT /links/1 # PUT /links/1.xml def update @link = Link.find(params[:id]) respond_to do |format| if @link.update_attributes(params[:link]) flash[:notice] = 'Link was successfully updated.' format.html { redirect_to manage_link_url(@link) } format.xml { head :ok } else format.html { render :action =&gt; "edit" } format.xml { render :xml =&gt; @link.errors, :status =&gt; :unprocessable_entity } end end end # DELETE /links/1 # DELETE /links/1.xml def destroy @link = Link.find(params[:id]) @link.destroy respond_to do |format| format.html { redirect_to manage_link_path } format.xml { head :ok } end end def find_user @user = session[:user] end end </code></pre> <p>why is the call to "edit_manage_link_path(link.id) giving me an error? I know that link.id actually returns a number, and if I hard code a value for the parameter instead of link.id, the function seems to run correctly</p>
 

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