0

I am using an instance variable, @week_starting, to display a table of the current week and have Twitter Bootstrap icons < > that I want to decrement / increment the week upon being clicked, then reload the current page. Suspect that the problem is partly in how I'm defining the variable in the controller. Won't this constantly be re-written? How can I fix this?

My instance variable in the controller is:

    @week_starting = Date.today.at_beginning_of_week

This is the code I'm using but clearly it is not correct.

[Helper Functions]

def increment_week(week_starting)
  week_starting += 7
end

def decrement_week(week_starting)
  week_starting -= 7
end

[View]
<%= link_to user_path(current_user, view: "prod"), {:onclick => increment_week(@week_starting)} do %>
    <i class="icon-chevron-right pull-right"></i>
<% end %>

HTML created:

<a href="/users/4?view=prod" onclick="2013-05-27">
    <i class="icon-chevron-right pull-right"></i>
</a>
collenjones
  • 510
  • 5
  • 19

1 Answers1

-1

This answer is what you are looking for.

Basically you need an AJAX call: It is a request triggered by javascript that change the data on the server and respond with an javascript that is executed to update your div.

Community
  • 1
  • 1
fotanus
  • 19,618
  • 13
  • 77
  • 111
  • Do I need to modify the data on the server? I was hoping to just modify the instance variable (a date) and then pull information from the server based on that date and the 'show' method. – collenjones Apr 29 '13 at 15:05
  • sorry, I understood your question wrong. @MrYoshiji has your answer - just use javascript. – fotanus Apr 29 '13 at 15:12