ea8e9901f4
Your branch is behind 'origin/strong-params' by 1 commit, and can be fast-forwarded. I'll pull to catch up after this commit Change code to whitelist params Remove attr_accessible lines Add strong_params to Gemfile, since this branch is still on Rails 3 Mixin to ActiveRecord::Base ActiveModel::ForbiddenAttributesProtection Use an initializer for the mixin
43 lines
1.0 KiB
Ruby
43 lines
1.0 KiB
Ruby
class MessagesController < ApplicationController
|
|
|
|
def index
|
|
@messages = current_user.messages
|
|
@message = Message.new
|
|
end
|
|
|
|
def show
|
|
@message = Message.where(:id => params[:id]).first
|
|
end
|
|
|
|
def destroy
|
|
message = Message.where(:id => params[:id]).first
|
|
|
|
if message.destroy
|
|
flash[:success] = "Your message has been deleted."
|
|
redirect_to user_messages_path(:user_id => current_user.user_id)
|
|
else
|
|
flash[:error] = "Could not delete message."
|
|
end
|
|
end
|
|
|
|
def create
|
|
if Message.create(params[:message])
|
|
respond_to do |format|
|
|
format.html { redirect_to user_messages_path(:user_id => current_user.user_id) }
|
|
format.json { render :json => {:msg => "success"} }
|
|
end
|
|
else
|
|
respond_to do |format|
|
|
format.html { redirect_to user_messages_path }
|
|
format.json { render :json => {:msg => "failure"} }
|
|
end
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def message_params
|
|
params.require(:message).permit(:creator_id, :message, :read, :receiver_id)
|
|
end
|
|
end
|