ROR中的堆栈级别太深

时间:2013-12-01 10:03:09

标签: ruby-on-rails

我正在学习ROR,我有Rails 3。 我有以下控制器的动作

def create
@album=Album.new
@album.title='Aftermath'
@album.artist='The Rolling Stones'
@album.release_date='1966/01/01 12:00:00'
@album.genre='Rock'
@album.save() #save!() doesno't event work
#render(:action => 'show_album' )

端 当我在浏览器中调用它时会抛出异常 堆栈级别太深

TinyTds::Error: Attempt to initiate a new Adaptive Server operation with results pending: EXEC sp_executesql N'SELECT @@TRANCOUNT'

在10823ms完成500内部服务器错误

ActiveRecord::StatementInvalid (TinyTds::Error: Attempt to initiate a new Adaptive             
Server operation with results pending: EXEC sp_executesql N'SELECT @@TRANCOUNT'):
app/controllers/public_controller.rb:24:in `create'

这是我遗失或未覆盖的内容,请指导。

1 个答案:

答案 0 :(得分:0)

好的,所以你要保存一个条目&您收到了Stack Level Too Deep错误

此错误基本上意味着您的应用程序内存不足,而且我认为这取决于您的代码。这就是我要做的事情:

创建记录

def create
    @album = Album.create(:title => "Aftermath", :artist => "The Rolling Stones", :release_date => "1966/01/01 12:00:00", :genre => "Rock")
end

如果您没有从表单

接收数据,那就是这样

接收表单数据

如果您从网络表单接收数据,我会这样做:

#app/controllers/albums_controller.rb
def new
    @album = Album.new
end

def create
    @album = Album.new(album_params)
    @album.save
end

private
def album_params
    params.require(:album).params(:title, :artist, :release_date, :genre)
end



  #app/views/albums/new.html.erb
   <%= form_for @album do |f| $>
       <%= f.text_field :title %>
       <%= f.text_field :artist %>
       <%= f.select :release_date %> -> this needs to change
       <%= f.select :genre %>  -> this needs to change
       <%= f.submit %>
   <% end %>
相关问题