I'll try to be brief.
I have a rails 4 products catalog and I want provide the user an option to set if he wants to see products with or without stock by default.
My approach to show products with or without stock is by a query parameter, so I have an URL like this to show earphones with stock:
http://localhost:3000/categories/earphones?sto_with_stock=t
And this one for those with no stock:
http://localhost:3000/categories/earphones
So my question is: is there a way to set that additional query param in the routes file, if the user matches the condition? I want to avoid changing the URL in every single link_to function. Also, I need to keep my filtering schema untouched.
Thank you so much.
Both your URLs points to the same controller action. The reason you can see the params in the url is because, it is a GET request. If you want two seperate URLs , declare another method and define another route to the same.
Related
I have a main page and special information for this particular page, how to better implement the editing form at url, for example / home-page-edit / without /: id?
You can do something like this.
1. Fetch edit page and form with the passed params: id, and_other_params
2. After loading edit form for specific resources based upon that params od value you can insert data.
3. Custom update action but updated based upon passed params and id.
** Please this may not be the ideal way for http-rest requests. Try to avoid this way.
In my application, users will be able to create categories and I would like the "breadcrumb" to be visible in the URL, i.e.
www.domain.com/user/:user_id/folder/:top-folder-slug/:sub-folder-slug/:sub-sub-folder-slug
I do not intend to have a limit on the levels of sub-folders a user can create so I'm needing to know if it is possible to define a route in Rails that will accept an unknown amount of folder parameters and, idealy, make them available to me with a sequential number appended to the params (params[folder1], params[folder2]). Is this possible?
This presents another challange as to how to store the entire breadcrumb in the database, as I can't just dynamically add "folder 1", "folder 2", etc, columns as needed and I'm not sure the performance/scalability of storing it all in jsonb column. Perhaps it would be necessary to only display parent-folder and current-folder in the URL and database, (i.e. below) and just query base on those?
www.domain.com/user/:id/folder/.../parent-folder/current-folder
Any insight on how to get to where I'm after would be appreciated.
I am trying to build a custom 'category' page displaying the products (car parts) that are linked to a certain type of vehicle.
My current URL looks like this:
http://prestashop.dev/cars?manufacturer=BMW&model=3%20Series&year=2003&engine-type=Petrol&engine-size=1.8
But I need it to look like this:
http://prestashop.dev/cars/manufacturer-BMW/model-3-Series/year-2003/engine-type-Petrol/engine-size-1.8
How is this possible? I don't want to go and create a custom URL in the SEO & URLs section for every possible combination as the manufacturer BMW has multiple models each having multiple years, etc.
Also, it needs to be able to move around in the url. Ie: if they only provide a manufacturer and a year, the url must be:
http://prestashop.dev/cars/manufacturer-BMW/year-2003
Any idea on how to do this inside of the module in Prestashop 1.6?
As per our knowledge, it is not possible to achieve this in PrestaShop. We recommend you to use hash in the URL and to make URL SEO friendly don't forget to use ! after hash.
You can check the same by visiting the following URL:
https://www.1motoshop.com/parts#!2015--Harley-Davidson--FLTRXS-Road-Glide-Special
Say I have a list of orders I want to display. I want to give the user the ability to show all orders, all orders from a certain state, and all orders from a certain category. Each of these can be filtered by a date range.
Without worrying about routing, I might just add each on the query string:
/orders?State=TX&Category=Books&DateRange=Yesterday
While I could easily make this work, it doesn't "feel" like this is the correct MVC-way of doing things.
I could have routes that look something like this:
/orders/
/orders/state/{state}
/orders/category/{category}
/orders/state/{state}/category/{category}/
/orders/state/{state}/category/{category}/Date/{date-range}
But I'd still want to support each of those filters not being there. Is there a better way of handling this or am I just over thinking the whole thing?
If I go the URL only path, it isn't clear how I would create these routes without just repeating them for all the combinations I would want (state, no category, date, state, no category, no date, no state, category, date, etc.)
I think the query parameter version is fine for MVC. What's probably confusing you is that, when you want to give the user a page for a specific order, you do put the order_id in the page. So where in a traditional website, you'd just make that URL
/order.html?order_id=1234
(or whatever), with MVC you want to use
/orders/1234
instead. The difference is, you only want to put mandatory parameters --- those that the page would break without --- in the URL; not every parameter. You can't return an order page without an order id, so that goes in the URL.
You can have both on a page; for a silly example, if you had a shipping tracking page for an order, you could have a URL like
/orders/1234/tracking?since=9%3a00
to only show tracking events (arrived at, departed at) since 9:00am.
It's actually a common practice to leave search/filter options in query parameters, look on google for instance.
From my point of view, unless you care about seo on filter results or want to have human friendly urls for this page, the is no point in supporting routes for any possible filter.
I have a detail page that gets called from various places and has a nice readable url like
"www.mypage.com/product/best-product-ever".
The calling pages (list of products) have a more complex url like:
"www.mypage.com/offers/category/electronic/page/1/filter/manufacturer/sony/sort/price" and
"www.mypage.com/bestseller/this-week".
How can I make a backlink from the detailpage to the calling product list?
I cannot use javascript
I don't want to have the calling page in the URL, because it gets to long
I really want links between pages, no http-post
I cannot use Sessionstate
EDIT:
Sessionstate is ruled out, because if there are 2 Windows open, then they would share the same "Back" page information.
Like Lee said, use the referrer value:
Back
If you don't want the URL in the link because it's too long, try running some sort of simple compression algorithm over the URL, display the compressed data as unicode text and then append the compressed URL as a parameter to a redirect page, e.g:
Back
What about using the referrer header value?
Here's a crazy idea that will require a fair but of work and may not be healthy for performance (depending on your users).. but here we go:
Create a repository for caching 'ListResults' (and wire it to persist to the DB of you like.. or just leave it in memory on the server).
In short what this Repo can do is store a ListResult which will include everything to persist the state of the current view of the list any given user is looking at. This might include routes and other values.. but essentially everything that is needed to redirect back to that specific page of the filtered and sorted list.
As the ListResult item is added to the repo a small unique hash/key is generated that will be url friendly - something like this "k29shjk4" - it is added to the item along with a datetime stamp.
ListResults are only persisted from the moment a list gets off the default view (ie. no filtering, sorting and Page 1) - this will help in a small way for performance.
A ListResult item may never actually get used but all detail actionlinks on the particular list view have the ListResult.Key hash value added to the route. So yes, it might end up as a querystring but it will be short (url friendly) and if you wanna mess with routes more, you can tidy it up further.
For navigation "back" to the list, you may need a new small controller which accepts simply the ListResult.Key hash value and redirects/re-creates the state of the list view (paging, filtering and sorting included) from the lookup in the repo.
So we have met the requirements so far: no calling page in the url (in the sense that its not the whole page - just a hash lookup of it); no POSTing, no sessions, no js.
To stop the ListResult repo from getting to big (and dangerous: if you persist it to the DB), you can use a ASP.NET background service to periodically prune the 'old' routes by way of the timestamp.. and 'extend' the life of routes that are continuously being used by adding time to the stamp of a ListResult item when it's requested via the new controller. No need to persist a route indefinitely coz if a user wants a permalink to a list view, they can bookmark the long list route itself.
hope this helps somehow
Do you have a cookie?
If so, you can put it in there, or use it to create your own session state.
I think this is more like a "Back to results" then a generic "<< back" link, because you would expect the generic back link to return to the genetic list, not the heavily filtered list you described, right?
I don't know if this falls into your "no post" condition, but the only option I can see is having the Detail action be POST-only ([AcceptVerbs(HttpVerbs.Post)]) and include another parameter like string fullRoute which is converted to the 'link' on the detail page for "Back to results". Overload the Detail action missing the fullRoute param and have the overloaded action be a GET action so that the POST fullRoute value is not required (for when users are ok with the 'generic' "Back" link). This should serve both 'generic' GET requests to the Detail page and the POST request which will include the specific "Back to results" link for the filtered list.