有一个联系页面,提供输入姓名,电话,电子邮件和消息,然后发送给管理员的电子邮件.没有理由在DB中存储消息.
题.如何:
在控制器中使用Rails验证,完全不使用模型,或者
在模型中使用验证,但没有任何数据库关系
UPD:
模型:
class ContactPageMessage
include ActiveModel::Validations
include ActiveModel::Conversion
extend ActiveModel::Naming
attr_accessor :name, :telephone, :email, :message
validates :name, :telephone, :email, :message, presence: true
validates :email, email_format: { :message => "???????? ?????? E-mail ??????"}
def initialize(attributes = {})
attributes.each do |name, value|
send("#{name}=", value)
end
end
def persisted?
false
end
end
Run Code Online (Sandbox Code Playgroud)
控制器:
def sendmessage
cpm = ContactPageMessage.new()
if cpm.valid?
@settings = Setting.first
if !@settings
redirect_to contacts_path, :alert => "Fail"
end
if ContactPageMessage.received(params).deliver
redirect_to contacts_path, :notice => "Success"
else …
Run Code Online (Sandbox Code Playgroud) 我有简单的控制器:
angular.module('it.works', ['ngResource'])
.controller 'ItWorksCtrl', ($scope, Task) ->
$scope.worksTable = {
data: Task.query(),
columnDefs: [
{ field: "created_at", cellFilter: "date:'dd.MM.yyyy'", displayName: '???? ????????' },
{ field: "task", cellFilter: "limitTo:300", displayName: '???????? ??????' },
{ field: "performer", displayName: '???????????' },
{ field: "task_type", displayName: '?????????' },
{ field: "is_orgtechnik_task", displayName: '??????????', cellTemplate: "<div class='ui-grid-cell-contents'><i class='fa {{ COL_FIELD == true && \"fa-check\" }}'></i></div>" },
{ field: "department", displayName: '?????????????' },
{ field: "customer", displayName: '????????' },
{ field: "customer_telephone", displayName: '??????? ?????????' …
Run Code Online (Sandbox Code Playgroud)