How to customize sort action in rails_admin - ruby-on-rails

I'm using rails_admin. Unfortunately I can't get to override a sort action on a specific model. I just want to show all users (sort action, when the title is clicked) created_at 1 day ago or etc. Any idea?

I am expecting that you want a custom filter which allows user to select options like "One Day Ago", "One Week Ago", "One Month Ago".
Yes you can implement this functionality using the scoping the queries. Here is the link for same. Scoping Queries
Also if you want to customize the values displayed in the column the you can take a look at this Railscast Active Admin Episode
In this video they have explained the column customization for price column (from 4.25 to 7.15).

Related

Google Sheets sorting by time

So I am in charge of office hours for a class at my University. I have to send out a google form every week for the students to sign up. The way the form is sent back, the data is grouped by Name, and the times they are available are grouped by days.
To make it easier on myself, I want to group it by times. Basically, I want it so that each day/time will have its own row, and the names of the people who want the time slot would be grouped together in the adjacent column.
I already separated the groups of times so that each time has its own cell, but I cannot figure out how to regroup the data by time.
I should also mention that each session of OH is 30 minutes and that each student can only receive one session of office hours a week because of limited availability. I also need to group the sessions into blocks so that the teachers won't have idle time (basically a teacher will have office hours from 5:00-6:30 PM on Tuesday, instead of 5:00-5:30 PM and 6:00-6:30 PM on Tuesday and 8:00-8:30 PM on Thursday). Grouping the names of the people who want office hours by the times that they are available would make it a lot easier to set up that week's office hours schedule.
Here's a link to an example:
https://docs.google.com/spreadsheets/d/1fRYYNUoEcgynU9cDMoXzsyjtIir4hsRlfFYJau36a78/edit?usp=sharing
have a look at this sheet ( i have only turned on sharing temporarily, co copy this to your own drive)
Look at the "matrix choices" sheet.
I created a Matrix of students and times (which I think is better), but there is also a list of names for each timeslot on the end too.
have a play changing some of the 1's (sessions applied for) to "G" (short for Granted). Ive set up some conditional formatting and data validation.

Create a date range dropdown with Ransack

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

Weekly scheduling in Rails

I want to allow teachers to be able to login to my Rails 3.2 app and be able to set when they are available. So instead of having two datetime fields where an actual date is stored is stored for starts_at and ends_at, I'd like for them just to say I'm available on "Mondays between 4:00pm and 5:00pm" with all three values being dropdowns.
The orignal way I approached this was having a string for day and using the time_select method in my form for my starts_at and ends_at. Unfortunately, time_select still comes with the date.
I'm just looking for the cleanest way to allow weekly scheduling. Is this possible? If it is, is there an easier way to do this? Thanks in advance for your tips.
take a look at
https://github.com/mzararagoza/rails-fullcalendar-icecube
its a small appointment app that i think that you can take allot out of it.

Separate a input into 2 parts

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.

Highcharts on Rails 3

I am quite new to Rails, and I need to work on a report generating plugin using Rails and Highcharts for the output. My main issue is that my user is meant to be able to define a time range using a jQuery datepicker. How can I get the highcharts graph on the x axis to reflect the time range based on the users selection, and how do I tie it to the other fields in the rails model.
Eg. If I have a table with a created_by field which the user is supposed to pick his to and from dates from... and the table also has user_id and the users select a specific language for each application. I want the graph to show for each day the count of the different languages different users selected during their application.
Hope my question is clear enough. Thanks
You should look at: http://railscasts.com/episodes/223-charts

Resources