Jquery 从头开始编写我的第一个json,但我似乎无法理解这个简单的部分
哈默: 控制器:Jquery 从头开始编写我的第一个json,但我似乎无法理解这个简单的部分,jquery,ruby-on-rails,ruby,json,haml,Jquery,Ruby On Rails,Ruby,Json,Haml,哈默: 控制器: = link_to 'redeem', redeem_admin_organization_path(organization), :class => 'button_short live redeem' 赎回.js.haml: def redeem @organization = Organization.find(params[:id]) @organization.update_attribute('accumulated_credits', '0') e
= link_to 'redeem', redeem_admin_organization_path(organization), :class => 'button_short live redeem'
赎回.js.haml:
def redeem
@organization = Organization.find(params[:id])
@organization.update_attribute('accumulated_credits', '0')
end
这将返回错误:
== $("#organization_#{@organization.id} .redeem").html("#{escape_javascript(link_to('redeem', redeem_admin_organization_path(@organization), :class => 'button_short live redeem'))}");
看起来错误与haml或json无关-我认为它在@organization.cumulated_credits分配中;看起来它不存在 您是否可以通过schema.rb或使用控制台来确认是否存在
NoMethodError (undefined method `accumulated_credits=' for #<Organization:0x2f3242c>):
啊哈!我只能在IRB中检索此数据,例如Organization.first.Consumerated_credits返回0。但是如果我做Organization.first.update_属性'Cumultived_credit','0',它会给出与上面相同的错误。那是什么意思?我明白了。这是因为此属性未附加到此模型。因此问题是:D,但你的指针让我明白了。谢谢
@organization.update_attribute('accumulated_credits', '0')
...
NoMethodError (undefined method `accumulated_credits=' for #<Organization:0x2f3242c>):