`
wuhuizhong
  • 浏览: 688698 次
  • 性别: Icon_minigender_1
  • 来自: 中山
社区版块
存档分类
最新评论

Creates/updates a record from hash

    博客分类:
  • ROR
阅读更多

 

def create_or_update_record(params)
        hsh = ActiveSupport::JSON.decode(params[:data])
        hsh.merge!(config[:strong_default_attrs]) if config[:strong_default_attrs]
        @record ||= data_class.find(:first, :conditions => {data_class.primary_key => hsh.delete(data_class.primary_key)}) # only pick up the record specified in the params if it was not provided in the configuration
        success = true

        @record = data_class.new if @record.nil?

        hsh.each_pair do |k,v|
          begin
            @record.send("#{k}=",v)
          rescue StandardError => exc
            flash :error => exc.message
            success = false
            break
          end
        end
        # Corey
        if session[:netzke_user_id]
          user = User.find(session[:netzke_user_id])
          @record.user_id = user.id
          # did we have complete success?
          success && @record.save
        else
          flash :error => "您必須先登錄才能异动资料!"
          success = false
        end
   
       
end

分享到:
评论

相关推荐

    用OpenGL 导入 3DS 源文件

    AppWizard creates one document type and one view: 3DSLoaderDoc.h, 3DSLoaderDoc.cpp - the document These files contain your CMy3DSLoaderDoc class. Edit these files to add your special document data ...

    图像处理中关于小波变换的源代码

    Microsoft Developer Studio reads and updates this file. ///////////////////////////////////////////////////////////////////////////// Other notes: AppWizard uses "TODO:" to indicate parts of the ...

    系统图像预览

    from the Microsoft Visual C++ CD-ROM onto the system or system32 directory, and rename it to be MFCLOC.DLL. ("XXX" stands for the language abbreviation. For example, MFC40DEU.DLL contains resources ...

    可以用来屏蔽热键的VC源代码

    from the Microsoft Visual C++ CD-ROM onto the system or system32 directory, and rename it to be MFCLOC.DLL. ("XXX" stands for the language abbreviation. For example, MFC42DEU.DLL contains resources ...

    华科VC++画图应用程序

    AppWizard creates one document type and one view: MyPenDoc.h, MyPenDoc.cpp - the document These files contain your CMyPenDoc class. Edit these files to add your special document data and to ...

    基于VC++的绘图程序

    AppWizard creates one document type and one view: DrawDemoDoc.h, DrawDemoDoc.cpp - the document These files contain your CDrawDemoDoc class. Edit these files to add your special document data and ...

    PICTURE GAME

    from the Microsoft Visual C++ CD-ROM onto the system or system32 directory, and rename it to be MFCLOC.DLL. ("XXX" stands for the language abbreviation. For example, MFC42DEU.DLL contains resources ...

    人工智能小游戏-基于alpha-beta剪枝算法实现的五子棋源码

    AppWizard creates one document type and one view: firDoc.h, firDoc.cpp - the document These files contain your CFirDoc class. Edit these files to add your special document data and to implement ...

    mydraw绘图软件

    AppWizard creates one document type and one view: MyDrawDoc.h, MyDrawDoc.cpp - the document These files contain your CMyDrawDoc class. Edit these files to add your special document data and to ...

    细胞模式统计识别的VC++实现

    AppWizard creates one document type and one view: CellDoc.h, CellDoc.cpp - the document These files contain your CCellDoc class. Edit these files to add your special document data and to implement ...

    串口采集实验

    from the Microsoft Visual C++ CD-ROM onto the system or system32 directory, and rename it to be MFCLOC.DLL. ("XXX" stands for the language abbreviation. For example, MFC42DEU.DLL contains resources ...

    sys_clip_4.zip

    from the Microsoft Visual C++ CD-ROM onto the system or system32 directory, and rename it to be MFCLOC.DLL. ("XXX" stands for the language abbreviation. For example, MFC40DEU.DLL contains resources ...

    MouseDemo鼠标作图

    AppWizard creates one document type and one view: MouseDemoDoc.h, MouseDemoDoc.cpp - the document These files contain your CMouseDemoDoc class. Edit these files to add your special document data ...

    二十四点源程序

    AppWizard creates one document type and one view: xieyuyingDoc.h, xieyuyingDoc.cpp - the document These files contain your CXieyuyingDoc class. Edit these files to add your special document ...

    MICROSOFT FOUNDATION CLASS LIBRARY

    from the Microsoft Visual C++ CD-ROM onto the system or system32 directory, and rename it to be MFCLOC.DLL. ("XXX" stands for the language abbreviation. For example, MFC42DEU.DLL contains resources ...

    人机对话系统源代码[考试]

    from the Microsoft Visual C++ CD-ROM onto the system or system32 directory, and rename it to be MFCLOC.DLL. ("XXX" stands for the language abbreviation. For example, MFC42DEU.DLL contains resources ...

    CustDlg.zip

    from the Microsoft Visual C++ CD-ROM onto the system or system32 directory, and rename it to be MFCLOC.DLL. ("XXX" stands for the language abbreviation. For example, MFC42DEU.DLL contains resources ...

    用VC|MFC编写的计算器

    from the Microsoft Visual C++ CD-ROM onto the system or system32 directory, and rename it to be MFCLOC.DLL. ("XXX" stands for the language abbreviation. For example, MFC42DEU.DLL contains resources ...

    用VC++编写的基于C的聊天系统

    from the Microsoft Visual C++ CD-ROM onto the system or system32 directory, and rename it to be MFCLOC.DLL. ("XXX" stands for the language abbreviation. For example, MFC42DEU.DLL contains resources ...

    MFC编职工管理系统

    from the Microsoft Visual C++ CD-ROM onto the system or system32 directory, and rename it to be MFCLOC.DLL. ("XXX" stands for the language abbreviation. For example, MFC42DEU.DLL contains resources ...

Global site tag (gtag.js) - Google Analytics