我在Controller中有一个示例Action.
def some_action
product = Product.new
product.name = "namepro"
if product.save
client.update_attribute(:product_id,product.id)
end
end
Run Code Online (Sandbox Code Playgroud)
如何为此代码添加事务?我尝试使用此示例代码:
def some_action
**transaction do**
product = Product.new
product.name = "namepro"
if product.save
client.update_attribute(:product_create,Time.now)
end
**end**
end
Run Code Online (Sandbox Code Playgroud)
但它产生了这个错误:
undefined method `transaction'
Run Code Online (Sandbox Code Playgroud)
我读到在控制器中使用事务是一种不好的做法,但我不知道原因是什么(http://markdaggett.com/blog/2011/12/01/transactions-in-rails/)
在该示例中,如果已创建并保存产品并且客户端更新失败... Rails必须不执行任何操作.
谢谢.
我将在Rails中开始一个新的Web项目(肯定也有一个phonegap应用程序),我想知道使用Couchbase和Rails是否是一个好主意.
我认为rails最好的东西之一就是activerecord.我相信改变这种行为并不是利用Rails的力量......但也许我错了.
有人用过这种组合吗?最好使用其他技术而不是使用Couchbase的Rails?
谢谢你的意见.
我希望在div显示(显示后)时调用一个函数.
有谁知道我怎么能这样做?我试着用这样的东西:
$(#someDiv).bind('show',function(){
alert('example')
});
Run Code Online (Sandbox Code Playgroud)
但我不确定我是否以正确的方式做到这一点,或者是否有可能实现这一目标.有任何想法吗?
我有一个rails应用程序,我的用户可以使用Devise gem和Omniauth-facebook gem登录.他们可以是"普通"用户或Facebook用户.所有这一切都正常.
我在这个应用程序中的API也由门卫进行身份验证.从我的移动客户端,我可以发送用户和密码,他们可以使用access_token访问我的API.这工作正常.
现在,我希望我的Facebook用户能够通过他们的Facebook登录从移动应用程序访问我的API.有人知道我怎么能做到这一点?用facebook登录后,我将有一个令牌,我将能够访问有关用户的一些信息...但我如何连接到API?
注意:当您使用Facebook登录rails应用程序时,Devise会创建一个包含提供程序和uid字段的新用户.
有任何想法吗?非常感谢.
是否有更好的方法来忽略大写?
"Hello".start_with?("hell","Hell") #=> true
Run Code Online (Sandbox Code Playgroud)
我想检查一个数组中的字符串元素是否以另一个忽略大写的字符串开头,就像 LIKE %
在MySQL中一样.
我需要将两个参数(lv和位置)传递给Asynctask doInBackground方法,但我不知道它是怎么做的......
LoadSound.execute(lv,position)
class LoadSound extends AsyncTask<**[ListView,int]**, String, String>
Run Code Online (Sandbox Code Playgroud)
谢谢!
编辑:
我有一个listView.如果您单击项目播放声音(来自Internet).
我想用Asynctask显示progressDialog.
在doInBackground方法中,我有itemOnClick:
HashMap<String, String> o = (HashMap<String, String>) lv.getItemAtPosition(position);
Run Code Online (Sandbox Code Playgroud)
因此我需要传递lv和位置.
在 Rails 3 我有这个查询:
Supporter.includes(:person).where("concat(club_member_number, ' ', people.surname, ' ', people.name) LIKE ?", term)
Run Code Online (Sandbox Code Playgroud)
但是在 Rails 4 中,它通过了一个错误:
ActiveRecord::StatementInvalid Exception: Mysql2::Error: Unknown column 'person.surname'
Run Code Online (Sandbox Code Playgroud)
我如何更改它在 Rails 4 中工作的查询?
ruby ×2
activerecord ×1
android ×1
bind ×1
controller ×1
cordova ×1
couchbase ×1
devise ×1
doorkeeper ×1
facebook ×1
jquery ×1
mysql ×1
show ×1
string ×1
transactions ×1