在Rails URL中传递Datetime

时间:2015-01-28 01:05:41

标签: ruby-on-rails datetime escaping

我正在尝试将日期时间传递给我的控制器以启动更新。目前我已将控制器动作构建为:

    def editEvent
        editEvent = "UPDATE androidchatterdatabase.events SET campaign_id = " + params[:campaign_id].to_s + ", location_id = " + params[:location_id].to_s + 
                    ", time_of_event = " + params[:time_of_event].to_s + ", status = " + params[:status].to_s + ", removed = " + params[:removed].to_s + ", updated_at = NOW()
                    WHERE id = " + params[:event_id].to_s

        ActiveRecord::Base.connection.execute(editEvent)
    end

和路线为:

match '/editEvent/:event_id/:campaign_id/:location_id/:status/:removed/:time_of_event', to: 'requests#editEvent', via: 'get'

但是当试图通过日期时间时,即。月,日,年,小时秒,到URL,如:

http://localhost:3000/editEvent/1/350/250/0/1/2015-01-27T16:17:57+00:00

错误发生在:

Mysql2::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ':17:57+00:00, status = 0, removed = 1, updated_at = NOW() WHERE id = 1' at line 1: UPDATE androidchatterdatabase.events SET campaign_id = 350, location_id = 250, time_of_event = 2015-01-27T16:17:57+00:00, status = 0, removed = 1, updated_at = NOW() WHERE id = 1

如何将此转义为允许在URL中发送日期以进行更新?

0 个答案:

没有答案