2011-02-01 145 views

回答

0

所有你需要的是類似於下面的東西。我並沒有包括所有的Sendgrid則params的,因爲有這麼多,你就會明白我的意思了幾個:

class SendgridMessage < ActiveRecord::Base 
    serialize :attachments 
    ... 
end 

class SendgridMessagesController < ApplicationController 
    def create 
    SendgridMessage.create(:to => params[:to], :from => params[:from], :attachments => params[:attachments]) 
    end 
end 

Sendgrid會發個帖子/與PARAMS sendgrid_messages,和你的對象將是使用所有正確的字段(您將需要添加一些示例)和序列化附件創建,就像您正在尋找的那樣。

2

可以序列整個PARAMS哈希(或其它任何物體)

class SomeModel < ActiveRecord::Base 
    serialize :params 
    … 
end 

class SomeModelsController < Applicationcontroller 
    def some_action 
    SomeModel.create(:params => params) 
    end 
end 
相關問題