ruk·si

Ruby
Parameters as Context

Updated at 2015-08-08 17:18

You can emulate visitor context by passing in parameters to URLs. Don't do this on anything sensitive though, visitors might emulate this too.

Emulating time.

if params[:current_time]
  @current_time = Time.parse(params[:current_time])
else
  @current_time = Time.now
end

<% @end_time = Time.utc(2015, 12, 20, 0, 0) %>
<% if @current_time >= end_time %>
<% else %>
<% end %>

# http://localhost:3000/?current_time=2010-10-31

Emulating country.

if params[:country]
  @country = params[:country]
else
  @country = LibrayToGetCountryCode.getByIP
end