Add extra validation to messages and diary entries.
This commit is contained in:
parent
c04e9ccf95
commit
d3b42fef34
4 changed files with 17 additions and 16 deletions
|
@ -7,9 +7,9 @@ class DiaryEntryController < ApplicationController
|
||||||
def new
|
def new
|
||||||
@title = 'new diary entry'
|
@title = 'new diary entry'
|
||||||
if params[:diary_entry]
|
if params[:diary_entry]
|
||||||
@entry = DiaryEntry.new(params[:diary_entry])
|
@diary_entry = DiaryEntry.new(params[:diary_entry])
|
||||||
@entry.user = @user
|
@diary_entry.user = @user
|
||||||
if @entry.save
|
if @diary_entry.save
|
||||||
redirect_to :controller => 'diary_entry', :action => 'list', :display_name => @user.display_name
|
redirect_to :controller => 'diary_entry', :action => 'list', :display_name => @user.display_name
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,23 +7,15 @@ class MessageController < ApplicationController
|
||||||
def new
|
def new
|
||||||
@title = 'send message'
|
@title = 'send message'
|
||||||
if params[:message]
|
if params[:message]
|
||||||
to_user = User.find(params[:user_id])
|
@message = Message.new(params[:message])
|
||||||
body = params[:message][:body]
|
@message.to_user_id = params[:user_id]
|
||||||
title = params[:message][:title]
|
@message.from_user_id = @user.id
|
||||||
message = Message.new
|
@message.sent_on = Time.now
|
||||||
message.body = body
|
|
||||||
message.title = title
|
|
||||||
message.to_user_id = params[:user_id]
|
|
||||||
message.from_user_id = @user.id
|
|
||||||
message.sent_on = Time.now
|
|
||||||
|
|
||||||
if message.save
|
if @message.save
|
||||||
flash[:notice] = 'Message sent'
|
flash[:notice] = 'Message sent'
|
||||||
redirect_to :controller => 'message', :action => 'inbox', :display_name => @user.display_name
|
redirect_to :controller => 'message', :action => 'inbox', :display_name => @user.display_name
|
||||||
else
|
|
||||||
@message.errors.add("Sending message failed")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,8 @@
|
||||||
class DiaryEntry < ActiveRecord::Base
|
class DiaryEntry < ActiveRecord::Base
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
|
|
||||||
|
validates_presence_of :title, :body
|
||||||
|
validates_numericality_of :latitude, :allow_nil => true
|
||||||
|
validates_numericality_of :longitude, :allow_nil => true
|
||||||
|
validates_associated :user
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,8 @@
|
||||||
class Message < ActiveRecord::Base
|
class Message < ActiveRecord::Base
|
||||||
belongs_to :sender, :class_name => "User", :foreign_key => :from_user_id
|
belongs_to :sender, :class_name => "User", :foreign_key => :from_user_id
|
||||||
belongs_to :recipient, :class_name => "User", :foreign_key => :to_user_id
|
belongs_to :recipient, :class_name => "User", :foreign_key => :to_user_id
|
||||||
|
|
||||||
|
validates_presence_of :title, :body, :sent_on
|
||||||
|
validates_inclusion_of :message_read, :in => [ true, false ]
|
||||||
|
validates_associated :sender, :recipient
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue