Using permalink in URLs pointing to groups

This commit is contained in:
Maikel Linke
2015-05-28 11:27:06 +10:00
parent e4f93863fd
commit ff2eed7760
6 changed files with 16 additions and 6 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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)

View File

@@ -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

View File

@@ -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

View File

@@ -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