-2

我正在尝试在 rails 中运行 create 方法,以将项目插入数据库。我创建的代码如下:

def create
  @song = Song.create ( { :song => params[:song],
  :artist => params[:artist],
  :album => params[:album],
  :song_id => params[:song_id],
  :longitude => params[:longitude],
  :latitude => params[:latitude],
  :stream_url => params[:stream_url],
  :art_url => params[:art_url] } )

  respond_to do |format|
    if @song.save
      format.json { render :json => @song, :status => :created, :location => @song }
    else
      format.json { render :json => @song.errors, :status => :unprocessable_entity }
    end
  end
end

但是,我收到以下错误消息。如何确保我插入的是我想要的?

Started POST "/create" for 127.0.0.1 at Sun May 19 03:09:21 -0400 2013
Processing by SongsController#create as */*
Parameters: {"longitude"=>-72.6600766181946, "latitude"=>41.5570384662233, "album"=>"Get Lucky", "song"=>"Get Lucky", "artist"=>"Daft Punk", "stream_url"=>"http://api.7digital.com/1.2/track/preview?country=US&trackId=28905854&oauth_consumer_key=7dkn3ygtanwv", "art_url"=>"http://cdn.7static.com/static/img/sleeveart/00/026/861/0002686113_100.jpg", "song_id"=>28905854}
WARNING: Can't verify CSRF token authenticity
(0.1ms)  begin transaction
SQL (0.7ms)  INSERT INTO "songs" ("address", "album", "art_url", "artist", "created_at", "latitude", "longitude", "song", "song_id", "stream_url", "updated_at", "user") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)  [["address", "2-16 McConaughy Drive, Wesleyan University, Middletown, CT 06457, USA"], ["album", "Get Lucky"], ["art_url", "http://cdn.7static.com/static/img/sleeveart/00/026/861/0002686113_100.jpg"], ["artist", "Daft Punk"], ["created_at", Sun, 19 May 2013 07:09:21 UTC +00:00], ["latitude", 41.5570384662233], ["longitude", -72.6600766181946], ["song", "Get Lucky"], ["song_id", 28905854], ["stream_url", "http://api.7digital.com/1.2/track/preview?country=US&trackId=28905854&oauth_consumer_key=7dkn3ygtanwv"], ["updated_at", Sun, 19 May 2013 07:09:21 UTC +00:00], ["user", nil]]
(47.1ms)  commit transaction
(0.1ms)  begin transaction
(0.1ms)  commit transaction
Completed 201 Created in 664ms (Views: 1.8ms | ActiveRecord: 48.8ms)
4

1 回答 1

2

->Completed 201 Created

没有错误信息。记录已保存。

VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ...values ->...

这些问号是紧随其后的值的占位符。这是正常行为。

每个问号都按照读取顺序替换为以下值。向右滚动以查看这些值。看起来一切都在那里。

WARNING: Can't verify CSRF token authenticity

这是一个安全问题。你有没有包括<%= csrf_meta_tags %>在你的布局中?

于 2013-05-19T07:26:16.953 回答