How do I output a list of data in a specific order? - ruby-on-rails-3

Using Rails, I'm trying to display all of the 'fragments' in a given 'chapter', in the order of the 'print order' assigned to each fragment.
Here's what I'm using:
#chapter.fragments.order("printorder").each do |fragment|
And yes, this is all very, very new to me. :)
Thanks for your help!

Something like this? I'm not sure what print order is.
#fragments = #chapter.fragments.order("printorder desc")
#fragments.each do |fragment|

Related

Array stored as String - How to extract pieces of it?

I got a problem with a specific database where some tags from a user profile are stored as a String data type, and so far I have not figured out how to fetch data from this one.
Example String:
{"watch_intro": "Gifts from my family.", "favorite_brands_styles": ["Fossil","Tudor","Omega"]}
I am looking to query into this field and get something like below:
'Fossil, Tudor, Omega'
Any help would be appreciated, thanks.
Nevermind, found the answer:
array_to_string(PARSE_JSON(EXTRA_INFO):"favorite_brands_styles",', ') AS fav_brands

Rally API Fetch All Features under specific Epic

Hi I cannot find this anywhere and it seems so easy.
I am trying to get All the Features under specific Epic with Alteryx.
I am using this to get them all, but I want to make more precise.
https://rally1.rallydev.com/slm/webservice/v2.0/portfolioitem/feature?pagesize=2000
https://rally1.rallydev.com/slm/webservice/v2.0/hierarchicalrequirement?workspace=https://rally1.rallydev.com/slm/webservice/v2.0/workspace/....
Can anyone help please?
Got another solution but it is still not perfect:
First I am getting SubEpics
https://rally1.rallydev.com/slm/webservice/v2.0/portfolioitem/subepic?pagesize=2000&&start=1&query=(Parent.FormattedID = E101)
And then Features:
https://rally1.rallydev.com/slm/webservice/v2.0/portfolioitem/feature?pagesize=2000&query=(((Parent.FormattedID = SE104) OR (Parent.FormattedID = SE101)) OR ((Parent.FormattedID = 102) OR (Parent.FormattedID = 103)))
OK! Correct answer for Feature is :) Got it with help from SAGI GABAY from CA:
https://rally1.rallydev.com/slm/webservice/v2.0/portfolioitem/feature?pagesize=2000&&start=1&query=(Parent.Parent.FormattedID
= E101)
I have also asked about the User Stories level and going this way (Parent.Parent.Parent.FormattedID) doesn't work anymore but you can do this:
https://rally1.rallydev.com/slm/webservice/v2.0/hierarchicalrequirement?pagesize=2000&&start=1&query=(Feature.Parent.FormattedID = SE101)

Product Index Using Django ORM

I have a list of Products with a field called 'Title' and I have been trying to get a list of initial letters with not much luck. The closes I have is the following that dosn't work as 'Distinct' fails to work.
atoz = Product.objects.all().only('title').extra(select={'letter': "UPPER(SUBSTR(title,1,1))"}).distinct('letter')
I must be going wrong somewhere,
I hope someone can help.
You can get it in python after the queryset got in, which is trivial:
products = Project.objects.values_list('title', flat=True).distinct()
atoz = set([i[0] for i in products])
If you are using mysql, I found another answer useful, albeit using sql(django execute sql directly):
SELECT DISTINCT LEFT(title, 1) FROM product;
The best answer I could come up with, which isn't 100% ideal as it requires post processing is this.
atoz = sorted(set(Product.objects.all().extra(select={'letter': "UPPER(SUBSTR(title,1,1))"}).values_list('letter', flat=True)))

Unable to query using 4 conditions with WHERE clause

I am trying to query a database to obtain rows that matches 4 conditions.
The code I'm using is the following:
$result = db_query("SELECT * FROM transportesgeneral WHERE CiudadOrigen LIKE '$origen%' AND DepartamentoOrigen LIKE '$origendep' AND DepartamentoDestino LIKE '$destinodep' AND CiudadDestino LIKE '$destino%'");
But it is not working; Nevertheless, when I try it using only 3 conditions; ie:
$result = db_query("SELECT * FROM transportesgeneral WHERE CiudadOrigen LIKE '$origen%' AND DepartamentoOrigen LIKE '$origendep' AND DepartamentoDestino LIKE '$destinodep'");
It does work. Any idea what I'm doing wrong? Or is it not possible at all?
Thank you so much for your clarification smozgur.
Apparently this was the problem:
I was trying to query the database by using the word that contained a tittle "Petén" so I changed the database info and replaced that word to the same one without the tittle "Peten" and it worked.
Now, im not sure why it does not accept the tittle but that was the problem.
If you have any ideas on how I can use the tittle, I would appreciate that very much.

Magento, REST filter parametar 'from'?

when I call
$oauthClient->fetch($resourceUrl .. )
I need something like this
$resourceUrl = "www.myaps/api/rest/orders?filter[0][attribute]=created_at&filter[0][from][0]=2013-09-04 12:53:32";
But this doesn't work.
I need to take all order created after specific time? But I don't know how to use 'from' in rest API :(
Any help?
I found the answer
filter[0][attribute]=created_at&filter[0][from][0]=2012-09-04%2012:53:32"
The key is to use "%20" between date and time