Fix coding standards in application files

This commit is contained in:
Thibault Jouan 2015-04-30 08:52:00 +00:00
parent 737ac1f10a
commit 3b733c349e
16 changed files with 34 additions and 26 deletions

View File

@ -1,7 +1,7 @@
module API
class ApplicationController < ::ApplicationController
skip_before_filter :verify_authenticity_token
skip_before_filter :authenticate!, only: [:cor_preflight]
skip_before_filter :authenticate!, only: :cor_preflight
before_filter :cor_filter

View File

@ -5,14 +5,15 @@ module API
end
def create
@playlist = current_user.playlists.build(playlist_params)
@playlist = current_user.playlists.build playlist_params
@playlist.save
end
private
def playlist_params
params.require(:playlist).permit(:name)
params.require(:playlist).permit :name
end
end
end

View File

@ -1,11 +1,11 @@
module API
class SessionsController < ApplicationController
skip_before_filter :authenticate!, only: [:create]
skip_before_filter :authenticate!, only: :create
def create
user = User.find_by_email(params[:session][:email])
unless user.try(:authenticate?, params[:session][:password])
unless user.try :authenticate?, params[:session][:password]
return render json: '', status: :not_found
end

View File

@ -2,7 +2,7 @@ module API
class SoundsController < ApplicationController
# FIXME: add some tests!
def show
sound = Sound.find params[:id]
sound = Sound.find(params[:id])
send_file sound.path, type: sound.mime_type
end
end

View File

@ -3,7 +3,7 @@ class ApplicationController < ActionController::Base
before_filter :authenticate!
def current_user=(user)
def current_user= user
session[:user_id] = user.id
end
@ -11,6 +11,7 @@ class ApplicationController < ActionController::Base
@current_user ||= User.find(session[:user_id]) if session[:user_id]
end
protected
def authenticate!

View File

@ -1,6 +1,6 @@
class HomeController < ApplicationController
def index
@playlists = Playlist.all
@tracks = Track.latest
@playlists = Playlist.all
@tracks = Track.latest
end
end

View File

@ -8,7 +8,8 @@ class PlaylistsController < ApplicationController
end
def create
@playlist = current_user.playlists.build(playlist_params)
@playlist = current_user.playlists.build playlist_params
if @playlist.save
redirect_to action: 'index'
else
@ -22,6 +23,7 @@ class PlaylistsController < ApplicationController
def update
@playlist = Playlist.find(params[:id])
if @playlist.update_attributes playlist_params
redirect_to action: 'index'
else
@ -29,9 +31,10 @@ class PlaylistsController < ApplicationController
end
end
private
def playlist_params
params.require(:playlist).permit(:name)
params.require(:playlist).permit :name
end
end

View File

@ -1,9 +1,10 @@
class SessionsController < ApplicationController
skip_before_filter :authenticate!, only: [:new, :create]
skip_before_filter :authenticate!, only: %i[new create]
def create
user = User.find_by_email(params[:session][:email])
if user.try(:authenticate?, params[:session][:password])
if user.try :authenticate?, params[:session][:password]
self.current_user = user
redirect_to :root
else

View File

@ -1,6 +1,6 @@
class SoundsController < ApplicationController
def show
sound = Sound.find params[:id]
sound = Sound.find(params[:id])
send_file sound.path, type: sound.mime_type
end
end

View File

@ -1,6 +1,6 @@
class TracksController < ApplicationController
def show
@track = Track.find params[:id]
@track = Track.find(params[:id])
end
def new
@ -8,7 +8,8 @@ class TracksController < ApplicationController
end
def create
@track = Track.new track_params
@track = Track.new(track_params)
if @track.save
redirect_to @track
else
@ -19,6 +20,6 @@ class TracksController < ApplicationController
private
def track_params
params.require(:track).permit(:name, :file)
params.require(:track).permit %i[name file]
end
end

View File

@ -1,5 +1,5 @@
class UsersController < ApplicationController
skip_before_filter :authenticate!, only: [:new, :create]
skip_before_filter :authenticate!, only: %i[new create]
def new
@user = User.new
@ -7,6 +7,7 @@ class UsersController < ApplicationController
def create
@user = User.new(user_params)
if !@user.save
render :new
else
@ -18,6 +19,6 @@ class UsersController < ApplicationController
private
def user_params
params.require(:user).permit(:email, :password, :password_confirmation)
params.require(:user).permit %i[email password password_confirmation]
end
end

View File

@ -10,7 +10,7 @@ class Sound < ActiveRecord::Base
"#{Rails.configuration.sounds_path}/#{sha256}"
end
def file=(file)
def file= file
self.sha256 = Digest::SHA256.file(file.path).hexdigest
FileUtils.cp file.path, path
self.mime_type = file.content_type

View File

@ -3,8 +3,8 @@ class Track < ActiveRecord::Base
validates_presence_of :name
def file=(file)
sounds.build(file: file)
def file= file
sounds.build file: file
end
def sound

View File

@ -15,12 +15,12 @@ class User < ActiveRecord::Base
confirmation: true
validates_presence_of :password_hash
def password=(plain_password)
def password= plain_password
@password = plain_password
self.password_hash = Password.create(plain_password)
end
def authenticate?(password)
def authenticate? password
Password.new(password_hash) == password
end
end

View File

@ -1,4 +1,4 @@
= form_for(:session, url: sessions_path) do |f|
= form_for :session, url: sessions_path do |f|
%table
%tbody
%tr

View File

@ -1,4 +1,4 @@
= form_for(@user, url: users_path) do |f|
= form_for @user, url: users_path do |f|
- if @user.errors.any?
%ul
- @user.errors.full_messages.each do |m|