Ruby on rails ROR中的堆栈级别太深
我正在学习我有Rails 3的ROR。 我有以下控制器的动作Ruby on rails ROR中的堆栈级别太深,ruby-on-rails,Ruby On Rails,我正在学习我有Rails 3的ROR。 我有以下控制器的动作 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 => 'sho
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'
这是我遗漏或未涵盖的内容,请指导。好的,因此您试图保存一个条目&您得到的
堆栈级别太深
错误
这个错误基本上意味着你的应用程序内存不足,我认为这取决于你的代码。下面是我要做的:
创建记录
def create
@album = Album.create(:title => "Aftermath", :artist => "The Rolling Stones", :release_date => "1966/01/01 12:00:00", :genre => "Rock")
end
如果您没有从表单接收数据,则会出现这种情况
接收表单数据 如果您从web表单接收数据,我会这样做:
#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 %>
#app/controllers/albums_controller.rb
def新
@album=album.new
结束
def创建
@相册=相册。新建(相册参数)
@相册.保存
结束
私有的
def相册参数
参数要求(:唱片)。参数(:标题,:艺术家,:发行日期,:流派)
结束
#app/views/albums/new.html.erb
->这需要改变
->这需要改变
检查您的回调:您是否保存在其中一个回调中?您正在谈论哪些回调。我是ROR新手。你的代码真的,真的错了-我知道你是Rails新手,所以我会为你写一篇文章。我删除了答案,然后再次查找Rails中的堆栈级太深错误,发现它是由无限递归循环引起的——对我来说,这听起来像是缺乏记忆,从我的理解来看,堆栈级别太深
错误基本上是错误,即:“调用堆栈可能由有限的地址空间组成,通常在程序开始时确定。调用堆栈的大小取决于许多因素,包括编程语言、机器架构、多线程和可用内存量。”无限循环是个问题,不管你的记忆如何,它都会失败:记忆不是问题。你愿意我改变我的答案吗?我不在乎。这是错误的,但我们不能帮助这家伙,因为我们没有看到来源