ruby - Rails Deadline Calculator Help: future date = number input from user + date selected by the user -


i new ruby on rails , trying build deadline calculator works one: (click here).

as can see hyperlinked example, deadline calculator allow user enter given number form field reflecting number of days until deadline. deadline calculator add number given date selected user. calculator print resulting date of deadline based on these 2 user inputs.

example: imagine user receives letter stating, "you have 45 days 2/5/14 mail response letter...." , wanted calculate date equal 45 days after 2/5/14. user input "45" (days) , "2/5/14" (start date) , click "calculate" button. website display like, "your deadline saturday, march 22, 2014." here's have far....

my app/views/pages/about_page.html.erb file contains following block of code:

<div class="row">     <div class="col-xs-2">        <%= form_tag %>          <%= number_field_tag 'days' %>         <p>after</p>         <%= date_select('start', 'start_date') %>         <%= submit_tag 'calculate' %>       <% end %>        <div>         <%= @deadline %>       </div>      </div>   </div>  

my app/assets/controllers/pages_controller.rb file contains following blocks of code:

class pagescontroller < applicationcontroller  * * * *   def about_page     @days = params[:days]     @start = params[:start]     @deadline = 'print date x days after start date selected user.' end  * * * *   private     def page_params         params.require(:page).permit(:name, :position, :visible)     end 

so, question is, how rails add user's ":days" input user's "start" date input , print resulting "deadline" date? have searched endlessly solution, have yet find explains how calculate future date user inputs both start date , number of days after start date. please help!

you can add number of days date using + operator, like

date.today + 10 => sun, 16 feb 2014 

in case translate to

@deadline = date.new(params[:start][:year].to_i, params[:start][:month].to_i, params[:start][:day].to_i) + params[:days].to_i 

Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -