Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unexpected dot from helper method

I have the following routings

PosTracker::Application.routes.draw do
  get "home/index"

  resources :pos
  resources :apis

  match 'update_data' => 'home#update', :as => :update, :via => :get
  root :to => "home#index"

end

Now, when using the link_to helper method:

link_to "text", pos_path(starbase)

I get the following route /pos.13 instead of /pos/13. Obviously, this won't produce valid output. How can I fix this?

Edit: Relevant controller:

class PosController < ApplicationController
  # GET /pos
  # GET /pos.xml
  def index
    #do stuff        

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @pos }
    end
  end

  # GET /pos/1
  # GET /pos/1.xml
  def show
    @pos = Pos.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @pos }
    end
  end
end
like image 715
Femaref Avatar asked Mar 23 '26 10:03

Femaref


1 Answers

It seems to me like Rails is recognizing pos_path as your #index action url helper. Generally it will take the symbol you pass to resources and singularize it for a #show action.

The url helper you want to use would be

link_to "text", po_path(starbase)

You can generally find the name of the helper methods by running

rake routes

Or to get the helper for a specific controller

rake routes CONTROLLER=pos
like image 169
Cluster Avatar answered Mar 25 '26 05:03

Cluster