rails drop down to select the years from current year to past four years - ruby-on-rails-4

How do I create a drop down with a list of years beginning from current year and 4 years backward (2015, 2014... 2013)? and by default it should show the current year.

Agreed with Pavan but this would be much better
<%= select_year(Date.today, :start_year => Date.today.year, :end_year => Date.today.year-4) %>

You can use select_year. Something like below will do
<%= select_year(Date.today, :start_year => Date.today.year, :end_year => 2012) %>

Related

Trying to find a way to list all friday dates between 2 dates in powershell [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
How to identify a list of dates with a specific day of the week between 2 dates in Powershell
No problem, it's fairly straightforward:
$date = [datetime]::parseexact('07-Feb-20', 'dd-MMM-yy', $null)
$date2 = [datetime]::parseexact('28-Feb-20', 'dd-MMM-yy', $null)
$fridays = 1..($date2 - $date).Days | % {$date.AddDays($_)} | ? {$_.DayOfWeek -eq 'Friday'}
Just make sure you put your dates in correctly! There's likely a more succinct way to do it.
Every PowerShell [datetime] object contains a .DayOfWeek parameter which will tell you the day of the week. You can interate through the date items with another [datetime] feature, the .AddDays() method. So something like this:
$StartDate = [datetime]'datehere'
$EndDate = [datetime]'datehere'
$ThisDate = $StartDate
$AllFridays = #()
While ($ThisDate -le $EndDate)
{
If ($ThisDate.DayOfWeek -eq 'Friday') { $AllFridays += $ThisDate }
$ThisDate.AddDays(1)
}
This was just a first crack. Obviously, you could find the first friday, and then add days 7 at a time until you were past the End date, but I leave that optimization as an exercise for the reader. :)

How to add more columns to order records in grid in KENDO [duplicate]

This question already has answers here:
Sorting kendo grid on multiple columns
(3 answers)
Closed 5 years ago.
The question might be very simple but I have not found examples or documentation how to do order by multiple columns for KENDO grid. The part in the cshtml file is like this:
.ClientDetailTemplateId("addresses")
.DataSource(dataSource => dataSource.Ajax()
.Model(model => model.Id(m => m.Cid))
.Read(read => read.Action("SelectAddr", "Addr").Data("get_addr_grid_params"))
.PageSize(20)
.Sort(sort => sort.Add(m => m.zipcode))
)
How can I add one more column to order by?
I think you are looking for this:
.Sort(x =>
{
x.Add(y=>y.DownloadDate).Descending());
x.Add(y=>y.DueDate).Descending());
}

Rails unexpectedly creating duplicated records

I need to create a new market "3.5" when the "0.5" closed. The problem is, for some reason, many times, and only on the live server it created duplicaded "3.5", exactly at the same time when it closed the 0.5 and opens the first 3.5. Is there any way to prevent duplicated records from being created? The majority of times it creates single records, but for some reason I can't figure out, sometimes it messes up.
Here is part of the problematic code:
######CLOSE 0.5 / OPENS 3.5
if self.markets.find_by_name('0.5') != nil then
if result.sum >= 1 && (self.markets.find_by_name('0.5').status == "live" || self.markets.find_by_name('0.5').status == "pre-live")
if self.markets.find_by_name('0.5').settle_temp.to_i == 6
selection = "Over 0.5 Goals"
if self.markets.find_by_name('0.5').status == "live" || self.markets.find_by_name('0.5').status == "pre-live"
self.markets.find_by_name('0.5').close(selection)
end
if self.markets.find_by_name('3.5') == nil then
self.markets.create!(name: "3.5", status: "live")
end
else
self.markets.find_by_name('0.5').increment!(:settle_temp)
end
end
end
Don't know your exact situation, but maybe you could add unique constraint
on name and event_id fields pair? For example in the migration you could write:
add_index :markets, [:event_id, :name], :unique => true
In this way you'll be sure that there is just one markets record with desired name value.

RegEx for current year and anything between the current year plus 10

Im trying to create a regEx that will validate the current year and any year after that up to 10. So if the current year is 2015 the use can enter any year between 2015 and 2025. Is this possible?
I think it's simpler to just use x <= currentYear + 10 and x >= currentYear. A regular expression is definitely the wrong tool.
Regular expressions are not supposed to be used for numerical range checks, as #R. Martinho Fernandes suggested.
If you really, really need to use a regular expression, you could use something like so: \b20(1[5-9]|2[0-5])\b. You will need to change this every year.
I found a easy solution for this:
in the angular controller:
$scope.startTermDate = new Date();
$scope.startTermYear = $scope.startTermDate.getFullYear();
on the form input I used ng-minLength="startTerm":
<div data-ng-if="programEditForm.academicYear.$touched"
data-ng-messages="programEditForm.academicYear.$error">
<span class="help-block" data-ng-message="minlength">Cannot be less than current year</span>
</div>
Works pefect!!!

Is it possible to change the increment value for the "% Done" field

Redmine has a % Done field that is used to keep track of an issue's progress. By default, the list box contains values in 10% increments from 0-100. Is it possible to either change the listbox to a plain text field so I can enter in any integer from 0-100 or change the list box to display all integers from 0-100? I know I can create a custom field for this, but I want to use the built-in, if possible.
In your redmine installation look for the file
\app\views\issues\_attributes.rthml
The code for setting the 10% increment is on line 38 (Version 1.1.0)
<p><%= f.select :done_ratio, ((0..10).to_a.collect {|r| ["#{r*10} %", r*10] }) %></p>
Which appears to be creating an array 1 to 10 in steps of 1 which is then factored by 10 for the %. So there are several ways you could change the array list.
For example the following would give you a drop down selection with 5% steps
<p><%= f.select :done_ratio, ((0..10).step(0.5).to_a.collect {|r| ["#{r*10} %", r*10] }) %></p>
I've just tried it on a Redmine installation and using the step of 0.5 makes the percentage complete a real number rather than an integer. So to keep it an integer this will work
<p><%= f.select :done_ratio, ((0..100).step(5).to_a.collect {|r| ["#{r} %", r] }) %></p>
Going for every 1% may make the drop down list a little on the long side.
This code is also apparent in
\app\views\issues\_form_update.rthml
But I'm not sure where that is used.