Skip to content

Instantly share code, notes, and snippets.

@libryder
Created May 2, 2012 00:06
Show Gist options
  • Select an option

  • Save libryder/2572537 to your computer and use it in GitHub Desktop.

Select an option

Save libryder/2572537 to your computer and use it in GitHub Desktop.
def padded_store_link direction
user_store_ids = current_user.store_ids_for_client(@client)
client_store_ids = @client.stores.map(&:id)
sorted_user_store_ids = client_store_ids.select { |i| user_store_ids.include?(i) }
index = sorted_user_store_ids.index(@store.id)
puts "INDEX #{index}"
if direction == "next"
id = sorted_user_store_ids[index+1]
else
id = sorted_user_store_ids[index-1]
end
link_to "#{direction.capitalize} Store", {:action => 'edit_store',:id => id}, {:class => :admin}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment