mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Using permalink in URLs pointing to groups
This commit is contained in:
@@ -9,7 +9,7 @@ module Admin
|
||||
|
||||
def move_up
|
||||
EnterpriseGroup.with_isolation_level_serializable do
|
||||
@enterprise_group = EnterpriseGroup.find params[:enterprise_group_id]
|
||||
@enterprise_group = EnterpriseGroup.find_by_permalink params[:enterprise_group_id]
|
||||
@enterprise_group.move_higher
|
||||
end
|
||||
redirect_to main_app.admin_enterprise_groups_path
|
||||
@@ -17,7 +17,7 @@ module Admin
|
||||
|
||||
def move_down
|
||||
EnterpriseGroup.with_isolation_level_serializable do
|
||||
@enterprise_group = EnterpriseGroup.find params[:enterprise_group_id]
|
||||
@enterprise_group = EnterpriseGroup.find_by_permalink params[:enterprise_group_id]
|
||||
@enterprise_group.move_lower
|
||||
end
|
||||
redirect_to main_app.admin_enterprise_groups_path
|
||||
@@ -33,6 +33,12 @@ module Admin
|
||||
end
|
||||
alias_method_chain :build_resource, :address
|
||||
|
||||
# Overriding method on Spree's resource controller,
|
||||
# so that resources are found using permalink
|
||||
def find_resource
|
||||
EnterpriseGroup.find_by_permalink(params[:id])
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def load_data
|
||||
|
||||
@@ -7,6 +7,6 @@ class GroupsController < BaseController
|
||||
end
|
||||
|
||||
def show
|
||||
@group = EnterpriseGroup.find params[:id]
|
||||
@group = EnterpriseGroup.find_by_permalink(params[:id]) || EnterpriseGroup.find(params[:id])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -75,6 +75,10 @@ class EnterpriseGroup < ActiveRecord::Base
|
||||
address.zipcode.sub!(/^undefined$/, '')
|
||||
end
|
||||
|
||||
def to_param
|
||||
permalink
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def self.find_available_value(existing, requested)
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
.row.pad-top{bindonce: true}
|
||||
.small-12.medium-6.columns
|
||||
.groups-header
|
||||
%a{"bo-href-i" => "/groups/{{group.id}}"}
|
||||
%a{"bo-href-i" => "/groups/{{group.permalink}}"}
|
||||
%i.ofn-i_035-groups
|
||||
%span.group-name{"bo-text" => "group.name"}
|
||||
.small-3.medium-2.columns
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
collection @groups
|
||||
attributes :id, :name, :position, :description, :long_description, :email, :website, :facebook, :instagram, :linkedin, :twitter
|
||||
attributes :id, :permalink, :name, :position, :description, :long_description, :email, :website, :facebook, :instagram, :linkedin, :twitter
|
||||
|
||||
child enterprises: :enterprises do
|
||||
attributes :id
|
||||
|
||||
@@ -9,5 +9,5 @@
|
||||
%ul.bullet-list
|
||||
- for group in current_distributor.groups
|
||||
%li
|
||||
%a{href: main_app.groups_path + "/#/#group#{group.id}"}
|
||||
%a{href: main_app.groups_path + "/#{group.permalink}"}
|
||||
= group.name
|
||||
|
||||
Reference in New Issue
Block a user