I am pretty new to rails and ruby and still wrapping my head around the hole concept of rails.
What i want to do: I'm creating a shiftplanner with a view of one week and want to create a button that will show the next/last week.
What I did:
I have 3 tables that are relevant. shift, person and test (contains types of shifts) Where both Test and Peson have one to many relations to Shift.
In my controller I did the following:
def index
@todos = Todo.all
@shifts = Shift.all
@people = Person.all
@start_of_week = Date.new(2015,8,7)
@end_of_week = Date.new(2015,8,11)
view:
<% person.shifts.where(:date_of_shift => @start_of_week..@end_of_week).order(:date_of_shift).each do |shift| %>
<td>
<%="#{shift.test.name} #{shift.date_of_shift}"%>
</td>
<%end%>
My Idea was I would make a link where I would increment both Dates and refresh my Page
<a href="/todos/new">
Next Week
<% @start_of_week += 7 %>
<% @end_of_week += 7 %>
</a>
Unfortuately that doesn't work. Cause everytime I call the index function in my controller it sets the date on the default value.
And I'm pretty clueless how to fix this problem in a rails way. My only would be to somehow pass the dates as parameter to the index function or something like that.
the generell structure is: I scaffolded a Todo view/controller/db just for the sake of having a view / controller and my 3 databases.
Thx for the help. PS: I'm using the current version of ruby and rails on lubuntu15(schouldn't be really releveant^^)
Aucun commentaire:
Enregistrer un commentaire