我在 ruby on rails 上运行插入语句。但是失败了。这是代码:
class BookmarkController < ApplicationController
def index
if request.post?
@user_new = Bookmark.new(params[:user_new])
tags = @user_new.tags.split(",")
@user_new = Bookmark.new(params[:user_new])
query = "INSERT INTO bookmark (title , url, tags) VALUES (#{@user_new.title}, #{@user_new.url}, #{tags[0]}) "
Bookmark.connection.execute(query);
end
end
但输出是:
ActiveRecord::StatementInvalid in BookmarkController#index
SQLite3::SQLException: near ".": syntax error: INSERT INTO bookmark (title , url, tags) VALUES (abhir, www.mrabhiram.tumblr.com, tumblr)
谁能建议我使用 SQL 插入语句插入记录的正确方法?