0

I've created a model that I'm overriding the primary key on:

set_primary_key :SONumber

I'm also using to_param

def to_param
    self.SONumber
end

My route for this model is as follows:

resources :sales_orders

In the view when linking to show an individual record:

=link_to 'Open', sales_orders_path(so)

It's generating links with periods in them instead of slashes i.e.:

.../sales_orders.1234  instead of .../sales_orders/1234

What am I missing here? Did I do something wrong?

EDIT: From my routes:

sales_order GET    /sales_orders/:id(.:format)       sales_orders#show

EDIT 2: Reading this link, I can only assume I have a pluralization error, however, if I switch the view to:

=link_to 'Open', sales_order_path(so)

I get no route matches... I'd rather not manually define the route if there's a better way

Community
  • 1
  • 1
Jayson Lane
  • 2,828
  • 1
  • 24
  • 39
  • I'd try using lowercase letters as primary_key attribute since strings that start with uppercase letters are considered constants in ruby, that may cause some conflict there. – Erez Rabih Sep 18 '12 at 21:50

1 Answers1

1

Try this instead:

= link_to 'Open', sale_order_path(so) # sale instead of sales

sales_order_path(so) generates the path for index action with so.SONumber as format.

Take a look at this Rails Guide: http://guides.rubyonrails.org/routing.html#paths-and-urls

Lucca Mordente
  • 1,131
  • 7
  • 9
  • sales_orders_path generates a path to the index, after restarting the server,=link_to 'Open', sales_order_path(so) ended up working! – Jayson Lane Sep 19 '12 at 14:17