Add to_param to the Track model

And update the urls
This commit is contained in:
AEtherC0r3 2017-07-07 00:21:26 +03:00 committed by Stella Rouzi
parent 68fc750e9f
commit 9671696adf
10 changed files with 33 additions and 27 deletions

View file

@ -15,7 +15,7 @@ module Admin
def show def show
@url = if @track @url = if @track
toggle_user_track_admin_conference_role_path(@conference.short_title, @role.name, @track.name.tr(' ', '_')) toggle_user_track_admin_conference_role_path(@conference.short_title, @role.name, @track)
else else
toggle_user_admin_conference_role_path(@conference.short_title, @role.name) toggle_user_admin_conference_role_path(@conference.short_title, @role.name)
end end
@ -24,7 +24,7 @@ module Admin
def edit def edit
@url = if @track @url = if @track
track_admin_conference_role_path(@conference.short_title, @role.name, @track.name.tr(' ', '_')) track_admin_conference_role_path(@conference.short_title, @role.name, @track)
else else
admin_conference_role_path(@conference.short_title, @role.name) admin_conference_role_path(@conference.short_title, @role.name)
end end
@ -36,7 +36,7 @@ module Admin
if @role.update_attributes(role_params) if @role.update_attributes(role_params)
url = if @track url = if @track
track_admin_conference_role_path(@conference.short_title, @role.name, @track.name.tr(' ', '_')) track_admin_conference_role_path(@conference.short_title, @role.name, @track)
else else
admin_conference_role_path(@conference.short_title, @role.name) admin_conference_role_path(@conference.short_title, @role.name)
end end
@ -55,7 +55,7 @@ module Admin
state = user_params[:state] state = user_params[:state]
url = if @track url = if @track
track_admin_conference_role_path(@conference.short_title, @role.name, @track.name.tr(' ', '_')) track_admin_conference_role_path(@conference.short_title, @role.name, @track)
else else
admin_conference_role_path(@conference.short_title, @role.name) admin_conference_role_path(@conference.short_title, @role.name)
end end

View file

@ -39,6 +39,10 @@ class Track < ActiveRecord::Base
false false
end end
def to_param
short_name
end
private private
def generate_guid def generate_guid

View file

@ -22,19 +22,20 @@
%td %td
= role.description = role.description
- if role.resource_type == 'Track' - if role.resource_type == 'Track'
- track = Track.find(role.resource_id) = link_to role.resource.name, admin_conference_program_track_path(@conference.short_title, role.resource)
= link_to track.name, admin_conference_program_track_path(@conference.short_title, track)
%td %td
= role.users.pluck(:name).first(5).join ', ' = role.users.pluck(:name).first(5).join ', '
- if role.users.count > 5 - if role.users.count > 5
- if role.resource_type == 'Track'
= link_to '...', track_admin_conference_role_path(@conference.short_title, role.name, role.resource)
- else
= link_to '...', admin_conference_role_path(@conference.short_title, role.name) = link_to '...', admin_conference_role_path(@conference.short_title, role.name)
%td %td
.btn-group .btn-group
- if role.resource_type == 'Track' - if role.resource_type == 'Track'
- track_name = Track.find(role.resource_id).short_name = link_to 'Users', track_admin_conference_role_path(@conference.short_title, role.name, role.resource), class: 'btn btn-success'
= link_to 'Users', track_admin_conference_role_path(@conference.short_title, role.name, track_name), class: 'btn btn-success'
- if can? :edit, role - if can? :edit, role
= link_to 'Edit', track_edit_admin_conference_role_path(@conference.short_title, role.name, track_name), class: 'btn btn-primary' = link_to 'Edit', track_edit_admin_conference_role_path(@conference.short_title, role.name, role.resource), class: 'btn btn-primary'
- else - else
= link_to 'Users', admin_conference_role_path(@conference.short_title, role.name), class: 'btn btn-success' = link_to 'Users', admin_conference_role_path(@conference.short_title, role.name), class: 'btn btn-success'
- if can? :edit, role - if can? :edit, role

View file

@ -7,7 +7,7 @@
= @role.name.titleize = @role.name.titleize
- if can? :edit, @role - if can? :edit, @role
- if @track - if @track
= link_to 'Edit', track_edit_admin_conference_role_path(@conference.short_title, @role.name, @track.short_name), class: 'btn btn-primary pull-right' = link_to 'Edit', track_edit_admin_conference_role_path(@conference.short_title, @role.name, @track), class: 'btn btn-primary pull-right'
- else - else
= link_to 'Edit', edit_admin_conference_role_path(@conference.short_title, @role.name), class: 'btn btn-primary pull-right' = link_to 'Edit', edit_admin_conference_role_path(@conference.short_title, @role.name), class: 'btn btn-primary pull-right'
.text-muted .text-muted

View file

@ -8,7 +8,7 @@
Track Track
.row .row
.col-md-12 .col-md-12
= semantic_form_for(@track, url: (@track.new_record? ? admin_conference_program_tracks_path : admin_conference_program_track_path(@conference.short_title, @track.short_name))) do |f| = semantic_form_for(@track, url: (@track.new_record? ? admin_conference_program_tracks_path : admin_conference_program_track_path(@conference.short_title, @track))) do |f|
= f.input :name = f.input :name
= f.input :short_name, hint: "A short and unique handle for the track, using only letters, numbers, underscores, and dashes. This will be used to identify the track in URLs etc. Example: 'my_awesome_track'", input_html: { required: 'required', pattern: '[a-zA-Z0-9_-]+', title: 'Only letters, numbers, underscores, and dashes.' } = f.input :short_name, hint: "A short and unique handle for the track, using only letters, numbers, underscores, and dashes. This will be used to identify the track in URLs etc. Example: 'my_awesome_track'", input_html: { required: 'required', pattern: '[a-zA-Z0-9_-]+', title: 'Only letters, numbers, underscores, and dashes.' }
= f.input :color, input_html: {size: 6, type: 'color'}, required: true = f.input :color, input_html: {size: 6, type: 'color'}, required: true

View file

@ -20,7 +20,7 @@
- @tracks.each do |track| - @tracks.each do |track|
%tr %tr
%td %td
= link_to(admin_conference_program_track_path(@conference.short_title, track.short_name)) do = link_to(admin_conference_program_track_path(@conference.short_title, track)) do
= track.name = track.name
%td %td
= track.short_name = track.short_name
@ -54,9 +54,10 @@
%i.fa.fa-check %i.fa.fa-check
%td %td
.btn-group{role: "group"} .btn-group{role: "group"}
= link_to 'Edit', edit_admin_conference_program_track_path(@conference.short_title, track.short_name), = link_to 'Edit', edit_admin_conference_program_track_path(@conference.short_title, track),
method: :get, class: 'btn btn-primary' method: :get, class: 'btn btn-primary'
= link_to 'Delete', admin_conference_program_track_path(@conference.short_title, track.short_name), - if can? :destroy, track
= link_to 'Delete', admin_conference_program_track_path(@conference.short_title, track),
method: :delete, class: 'btn btn-danger', method: :delete, class: 'btn btn-danger',
data: { confirm: "Do you really want to delete #{track.name}? Attention: This track will be removed from all Events that have it set" } data: { confirm: "Do you really want to delete #{track.name}? Attention: This track will be removed from all Events that have it set" }
.row .row

View file

@ -9,7 +9,7 @@
Track Track
.row .row
.col-md-12 .col-md-12
= semantic_form_for(@track, url: (@track.new_record? ? conference_program_tracks_path : conference_program_track_path(@conference.short_title, @track.short_name))) do |f| = semantic_form_for(@track, url: (@track.new_record? ? conference_program_tracks_path : conference_program_track_path(@conference.short_title, @track))) do |f|
= f.input :name = f.input :name
= f.input :short_name, hint: "A short and unique handle for the track, using only letters, numbers, underscores, and dashes. This will be used to identify the track in URLs etc. Example: 'my_awesome_track'", input_html: { required: 'required', pattern: '[a-zA-Z0-9_-]+', title: 'Only letters, numbers, underscores, and dashes.' } = f.input :short_name, hint: "A short and unique handle for the track, using only letters, numbers, underscores, and dashes. This will be used to identify the track in URLs etc. Example: 'my_awesome_track'", input_html: { required: 'required', pattern: '[a-zA-Z0-9_-]+', title: 'Only letters, numbers, underscores, and dashes.' }
= f.input :color, input_html: {size: 6, type: 'color'}, required: true = f.input :color, input_html: {size: 6, type: 'color'}, required: true

View file

@ -21,7 +21,7 @@
- @tracks.each do |track| - @tracks.each do |track|
%tr %tr
%td %td
= link_to(conference_program_track_path(@conference.short_title, track.short_name)) do = link_to(conference_program_track_path(@conference.short_title, track)) do
= track.name = track.name
%td %td
= track.short_name = track.short_name
@ -34,7 +34,7 @@
%td %td
= track.state = track.state
%td %td
= link_to 'Edit', edit_conference_program_track_path(@conference.short_title, track.short_name), = link_to 'Edit', edit_conference_program_track_path(@conference.short_title, track),
method: :get, class: 'btn btn-primary' method: :get, class: 'btn btn-primary'
.row .row

View file

@ -23,4 +23,4 @@
= @track.description = @track.description
.row .row
.col-md-12.text-right .col-md-12.text-right
= link_to 'Edit Track request', edit_conference_program_track_path(@conference.short_title, @track.short_name), class: 'btn btn-primary' = link_to 'Edit Track request', edit_conference_program_track_path(@conference.short_title, @track), class: 'btn btn-primary'

View file

@ -209,17 +209,17 @@ feature 'Has correct abilities' do
expect(current_path).to eq root_path expect(current_path).to eq root_path
other_track = create(:track, program: conference.program) other_track = create(:track, program: conference.program)
visit admin_conference_program_track_path(conference.short_title, other_track.short_name) visit admin_conference_program_track_path(conference.short_title, other_track)
expect(current_path).to eq root_path expect(current_path).to eq root_path
visit edit_admin_conference_program_track_path(conference.short_title, other_track.short_name) visit edit_admin_conference_program_track_path(conference.short_title, other_track)
expect(current_path).to eq root_path expect(current_path).to eq root_path
visit admin_conference_program_track_path(conference.short_title, self_organized_track.short_name) visit admin_conference_program_track_path(conference.short_title, self_organized_track)
expect(current_path).to eq admin_conference_program_track_path(conference.short_title, self_organized_track.short_name) expect(current_path).to eq admin_conference_program_track_path(conference.short_title, self_organized_track)
visit edit_admin_conference_program_track_path(conference.short_title, self_organized_track.short_name) visit edit_admin_conference_program_track_path(conference.short_title, self_organized_track)
expect(current_path).to eq edit_admin_conference_program_track_path(conference.short_title, self_organized_track.short_name) expect(current_path).to eq edit_admin_conference_program_track_path(conference.short_title, self_organized_track)
visit admin_conference_roles_path(conference.short_title) visit admin_conference_roles_path(conference.short_title)
expect(current_path).to eq admin_conference_roles_path(conference.short_title) expect(current_path).to eq admin_conference_roles_path(conference.short_title)