Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions app/controllers/polls_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class PollsController < ApplicationController
load_and_authorize_resource only: [:new, :create, :edit, :update,
:destroy, :published]
before_action :admin_user, only: [:new, :create, :edit, :update, :destroy]
before_action :authenticate_user!

# GET /polls
Expand Down Expand Up @@ -100,9 +101,16 @@ def answer
end

private

def poll_params
params.require(:poll).permit(
:question, :published
)
end

def admin_user

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent indentation detected.

redirect_to(root_url)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use 2 (not 1) spaces for indentation.
Tab detected.

unless current_user.admin?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tab detected.

end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tab detected.

end
end
3 changes: 3 additions & 0 deletions app/helpers/users_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ def display_name(user)
user.hide_last_name? ? first_name(user) : user.name
end

def has_admin_rights

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename has_admin_rights to has_admin_rights?.

current_user.admin?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use 2 (not -1) spaces for indentation.
Tab detected.

end
end
11 changes: 5 additions & 6 deletions app/views/polls/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
.poll{'data-id' => poll.id}
%h2= poll.question
.publish
= if current_user.admin?
= render :partial => "polls/publish_link", :locals => {:poll => poll}.actions
= link_to 'Edit', edit_poll_path(poll)
= link_to 'Destroy', poll, method: :delete, data: { confirm: 'Are you sure?' }
= link_to 'Show', poll
= render :partial => "polls/publish_link", :locals => {:poll => poll}.actions

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [81/80]

= link_to 'Edit', edit_poll_path(poll) if has_admin_rights
= link_to 'Destroy', poll, method: :delete, data: { confirm: 'Are you sure?' } if has_admin_rights

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [105/80]

= link_to 'Show', poll

= link_to 'New Poll', new_poll_path if current_user.admin?
= link_to 'New Poll', new_poll_path if has_admin_rights