How many different product types do you envisage you will need? If not many
then just go with Jason's suggestion and have a controller/resource for
each.
Besides, a good human oriented e-commerce site will have hand crafted
category pages.
Hugh
On Mon, Nov 29, 2010 at 5:53 PM, Dmytrii Nagirniak
On 29 November 2010 17:46, Korny Sietsma wrote:
> Sigh. Yes, I know. But after 20+ years in the IT industry, I have spent
> far too much time wading through other developer's similar decisions. (And
> being forced to make similar compromises myself, of course...)
I guess it's always a trade-
Sigh. Yes, I know. But after 20+ years in the IT industry, I have spent
far too much time wading through other developer's similar decisions. (And
being forced to make similar compromises myself, of course...)
- Korny
On Mon, Nov 29, 2010 at 5:07 PM, Dmytrii Nagirniak wrote:
> On 29 November
On 29 November 2010 16:36, Korny Sietsma wrote:
> ... and what happens in 6 months time, when someone creates a product type
> called "foo" ?
>
In six months time the application might not exists, be different from what
it is now and the context will be absolutely irrelevant. He needs
the soluti
Blacklisting certain resource names is pretty common practice when you
adopt the "/fruits/new", "/fruits/delete", "/fruits/banana"
convention. If you choose to adopt that, there's no way around having
to making certain names invalid.
Unless of course you choose not to follow that convention. E.g.:
... and what happens in 6 months time, when someone creates a product type
called "foo" ?
Or will you build a whole pile of validators and special rules to make sure
you never make a product with the a type that matches a route? Seems ugly
to me.
- Korny
On Mon, Nov 29, 2010 at 4:25 PM, Dmytrii
On 29 November 2010 16:10, Korny Sietsma wrote:
> If you want to both match "/cars/123" and also match /foo/bar" where "foo"
> isn't a product type... then you have a big problem just waiting to happen,
> imho.
>
>
Not necessarily.
I think that the solution of Bayan Khalili will work pretty well
If you want to both match "/cars/123" and also match /foo/bar" where "foo"
isn't a product type... then you have a big problem just waiting to happen,
imho.
- Korny
On Mon, Nov 29, 2010 at 1:57 PM, Pat Allan wrote:
> I think the issue would more be the routing with the rest of the app -
> '/:ty
How about this?
In your routes file:
class ProductPathConstraint
def matches?(request)
Product.dynamically_generated_list_of_available_types.include?(request.params['type'])
end
end
MyAwesome::Application.routes.draw do
# ...
match ':type/:id' => "products#show", :constraints =>
Produ
You can restrict the params so the route doesn't over-match:
match '/:type/:id' => 'products#show', :type => /cars|trucks|boats/, :id
=> /\d+/
Ben
On 29 November 2010 13:57, Pat Allan wrote:
> I think the issue would more be the routing with the rest of the app -
> '/:type/:id' would matc
> resources :cars, :controller => "products"
> resources :trucks, :controller => "products"
>
> Cheers,
>
> Michael
This method also creates your path helpers, so you can then do
car_path(@product) and truck_path(@product) or if you have car and
truck models, a simple url_for(@product) will do th
I think the issue would more be the routing with the rest of the app -
'/:type/:id' would match a good number of paths you wouldn't actually want it
to.
I think Andy's got it spot on before - you do indeed use that route, but it
becomes your catch-all, at the end of your routes file.
There's
How about just:
match '/:type/:id' => 'products#show'
And then in ProductsController#show, use params[:id] and params[:type] ?
Ben
On 29 November 2010 09:44, Mark Ratjens wrote:
> The requirement is to have urls of the form
>
> /cars/23
>
> not
>
> /products/cars-23
>
> This will, of cour
Rails encourages REST resources as a convention?
Hope I got what you're asking correctly.
Seems like it's better in the long run to treat individual product types as
a resource. You might need the posts, puts n deletes in the long run.
On 29 Nov 2010 07:33, "Michael Gall" wrote:
On Mon, Nov 29
On Mon, Nov 29, 2010 at 9:44 AM, Mark Ratjens wrote:
> The requirement is to have urls of the form
>
> /cars/23
>
> not
>
> /products/cars-23
Assuming all of the IDs are in the 1 set/table, you can do something
with the routing like this
resources :cars, :controller => "products"
resources :truc
Then you've no choice but a catchall route at the end of routes.rb
that sends everything at that point to products controller.
You will have to deal with more manual approach of url generation.
On 29 November 2010 09:44, Mark Ratjens wrote:
> The requirement is to have urls of the form
>
> /cars/
The requirement is to have urls of the form
/cars/23
not
/products/cars-23
This will, of course, be my fall-back position if I can't get exactly what
is wanted.
Also, I'm already using friendly_id ... my id's aren't actually numeric, but
it doesn't change the problem. I've read though the frie
You could consider mapping the following route to products controller
/products/:type/:id
or have a look into friendly_id, which is along the same concept of
to_params, maybe use id like car-23, truck-37, boat-126
On 28 November 2010 23:52, Mark Ratjens wrote:
> Suppose I have an ActiveRecord c
Worth a try but it does have wider consequences. For example calling
product_path produces
product_url failed to generate from ...
It's the kind of thing that I'm looking for though. Perhaps I should just
override the default helps generated for the resource?
On Mon, Nov 29, 2010 at 12:16 AM, D
Hi Mark,
I think you can override to_param method on your Product to return different
URL:
class Product < ...
def to_param
"#{kind_of_product}/#{id}"
end
end
Not sure whether it's a good idea to redefine to_param to include slash, but
I guess it should do the job for you.
You might als
Suppose I have an ActiveRecord called Product. I can have different kinds of
products, say "cars", "trucks" and "boats." Because of the nature of the
app, there is no need to subclass product (i.e, the data and behaviour is
the same) ...
... but for SEO reasons I want to be able to generate links
21 matches
Mail list logo