I'm working on a web site and i wanna separate a input into two parts (two dropdown lists) and after that concatenate them together and afterwards put that value into my database.
It goes something like this:
I want users to input a product Age, and i want to give them a dropdown list where they can select a number and a dropdown list where they can select if it's a day, week or month.
So they can select something like "1" + "day" or "4" + "weeks", and have a "1 day" or "4 weeks" in my Age database column. How can i do this?
Not a direct answer to your question, and maybe OT, but I would suggest you use a Date column in your database. This will allow you you to perform comparisons (like before / after), and ordering in SQL.
You can always the distance_of_time_in_words and distance_of_time_in_words_to_now helpers (documentation) to generate human readable time like 4 days ago, etc.
Related
I have a report that produces twelve pages, one for each month of the year. The report's main query contains the month name.
Below it is a subquery that can have more than one row in it. Right now the content of the subquery is identical on all twelve pages. But that's not what I want.
Is it possible to 'grab' the month name from the main report's query and use it in the subquery? In other words, I want the month name to be relected in the subquery on each page.
My online research says no, but I'm hoping an expert knows better.
Use the MasterLinkFields and ChildLinkFields of the subreport control to filter the subreport.
And use the month value (1 to 12) to filter, not the month name as this is localised.
Imagine a list on the left filled with employees going down the spreadsheet and headers across the top based categorized on infractions that an employee might violate. this sheet is connected to another sheet which adds a one every time a form is submitted against the employee adding up for the quarter. So employee john smith has across his row would show a 0 if he never committed this infraction and add a 1 to the column each time he did so a row might look like this. John Smith 0 4 5 0 1
The goal is to show the experts name and infraction with how many times this infraction took place removing the infractions that he did not commit so ideally it would look like John Smith 4 5 1 and the header of each number would show what he did.
The goal is to make it much easier to see who did what essentially. There will be over 100 employees and alot of 0's so optically it would look better to distill in order to quickly identify who did what and how many times.
Any ideas?
V lookups and important ranges based on if this is greater than 0 is tedious and does not exactly pull what we want. Essentially omitting the 0s and just showing what an employee has done rather than what they have not done is the goal. All index and match formulas do not seem to specifically answer this problem
simple Index V lookups and matching formulas have been tried
Not able to reflect all three variables (employee/frequency/infraction) while not showing on a master list the people who did not commit the offense
There's a few ways you could set this up. I would set this up so it
Column A = Employee
Column B = Infraction
Column C = 1
Column D = Date
That way you can do a pivot summary and have the employees, with their infractions below their name and the months/years they occurred. Also you can adjust this table as necessary, such as filter by the employee name or by date or by infraction.
The added benefit is you could create a chart with all of these as filters, like cutoff a date range or pick an employee or infraction and it can show a bar graph of all the infractions by month or something like that.
I would agree that listing your data of infractions line by line (as they happen) and using a pivot table would probably be the easiest.
You could also use the AGGREGATE function to pull from a large database as well. This way you could type in an employees name, and a list of all infractions would pop up next to the name (or wherever you would want it) with as much detail as you would like. This way is more complex, but using both a pivot table and the AGGREGATE function might get you the best of both worlds (you could searching infraction types, dates, employees, employee types, and get all the details in the world if wanted).
Hope this helps!
JW
What I have is a website where I add collected data of every single shift in a factory's production lines. I add data like (Quantity in tonnes). What I want is to be able to have the data of for instance; the morning, late and night shift of the (Quantity in tonnes) which are in the Shift table and are present and visible in the Shift Index view all combined and added, and added in another page which is the Days Index page (Day contains the shifts, one day has 3 shifts), so I could see the 3 shifts' data summed up together into the data combined to see as the total output of the day.
For example, in the "Quantity in tonnes", I would like 7 + 10 + 12 (These are the inputs I already have and I have added through a form to the shifts index) to be summed up, and appear in the Days index page automatically without me interfering as "29" in the Quantity of tonnes columns in it.
How is that possible to do? I can't seem to figure out how to write the code for it so that it would loop over all the inputs and constantly give me the summed out outputs.
Let me know if you need to see any parts of my code and if there is anymore info I could add for you to understand.
Have a look at the groupdate gem, it allows you to group by day, week, hour of the day, etc.
Some code from your end would help, but here's an example use, if I wanted to get revenue for past 3 weeks:
time_range = 90.days.ago..Time.zone.now
total = Sales.where('status > 2').group_by_week(:date_scheduled, Time.zone, time_range).sum(:price)
I'm using Ransack for some simple searching of one of my models.
I would like to add a dropdown to the search with entries like 'Today', 'Yesterday', 'Current week', etc which would operate on the created_at field. Also it would be nice to have an entry in this dropdown to reveal 2 date boxes to pick a custom date range. How do I go about this?
One way that I can think of doing this is for the dropdown to populate the two (hidden) date boxes via JavaScript, I just don't know how I could easily reselect the proper entry in the dropdown when reloading the page.
use this
distance_of_time_in_words(obj.created_at,Time.now)+" ago"
This will return result like this:
about 2 hours ago
I'm working on an app that will allow users to search for any recordings we have in a database, organized by three values: agent (name), phone, and date. date is recorded as a datetime value. I want to provide advanced search features that will allow users to select time ranges following this guideline:
Year: entered into a text field
Month: entered into a text field
Day: entered into a text field
Hours: two select lists representing a range upper and lower bound
Minutes: two select lists representing a range upper and lower bound
I watched this Railscast for help on how to get started with the search logic, but I'm concerned because I don't know how to pass in dateparts into Rails queries. Normally you would run something like select date_part(hh, date) as date_hour from table_name to get the value of hour, but how would you do that in Rails, or in the way Ryan Bates suggests in his Railscast?
You may concat the values in the controller accessing them by the params and then parse to a datetime
Then DateTime.strptime allows you to specify the format and convert a String to a DateTime.