如果我在rails命令提示符下执行gem list rack-cache,那么它没有显示具有该名称的gem,但是如果我捆绑了show rack-cache,那么它给了我像/vendor/bundle/ruby/1.9.1/gems/rack这样的路径-cache-1.2存储gem的位置.
我没有理解这种行为,因为如果使用后一个命令在路径中存在gem,那么当我给出gem list rack-cache命令时它为什么不显示.有什么不同.
我的模型的cropping方法在循环中调用,在我更新控制器中用户的属性后,它永远不会结束.
User controller code-
def change_img
@user = current_user
#this triggers the model's after_update callback
@user.update_attributes(params[:user])
flash[:notice] = "Successfully updated Image."
render :action => 'crop'
end
Run Code Online (Sandbox Code Playgroud)
User Model code-
after_update :reprocess_avatar, :if => :cropping?
def cropping?
#this method is called infinitely why?
!crop_x.blank? && !crop_y.blank? && !crop_w.blank? && !crop_h.blank?
end
Run Code Online (Sandbox Code Playgroud)
一旦设置了crop_x,crop_y,crop_w和crop_h,该cropping方法将始终返回true,这将继续调用该reprocess_avatar方法.这可能是因为reprocess_avatar方法也在更新avatar用户表的属性.因此再次after_update触发导致循环.
更新后有没有办法只调用一次方法?
我试图找出 -
INPUT: String data = "506313B5EA3E";
OUTPUT: String data = "50:63:13:B5:EA:3E";
我试过用 -
java.util.Arrays.toString(data.split("(?<=\\G..)"))
Run Code Online (Sandbox Code Playgroud)
但输出是: [50, 6313B5EA3E]
我使用post代码将参数发送到我的rails服务器上
if (email.value != '' && password.value != '')
{
loginReq.open("POST","http://192.168.0.187:3000/users/sign_in");
var params = {
email: email.value,
password: password.value
};
loginReq.send(params);
}
Run Code Online (Sandbox Code Playgroud)
在rails服务器端,我在控制台上获得此输出 -
Parameters: {"password"=>"[FILTERED]", "email"=>"abcdefgh@gmail.com"}
Run Code Online (Sandbox Code Playgroud)
但我需要像这样的输出 -
Parameters: {"user"=>{"email"=>"abcdefgh@gmail.com", "password"=>
FILTERED]"}, "commit"=>"Sign in"}
Run Code Online (Sandbox Code Playgroud)
如何添加user如上所述的参数.
json ruby-on-rails parameter-passing titanium titanium-mobile
我想使用public_methodslist 设置类的成员值.但是在下面给出的代码中,"className.member"将不起作用,因为".member"不是ClassName类的成员.
在ruby中有没有办法以这种方式设置成员的价值?
代码如下:
membersArray = className.public_methods
membersArray.each {|x|
member = x.to_s
className.member = "some value"
end
}
Run Code Online (Sandbox Code Playgroud) 我试图调用getFailureDialog()接口的方法OnSelectedListener.该方法实现于MainActivity.java.但是当我调用该方法时,我得到空指针异常.
我知道它因为OnSelectedListener仍未初始化而你正在调用getFailureDialog()未初始化的对象.显然,接口方法永远不会被初始化.但那我如何getFailureDialog()从班上调用这个方法Common.java呢?
我只在下面放置相关的源代码 -
源代码:
SharedFragment.java
public class SharedFragment extends DialogFragment
{
Bundle bundle = getArguments();
final String email = bundle.getString("email");
Thread t=new Thread(new Runnable()
{
public void run() {
common.myRecord(email);
}
}); t.start();
}
Run Code Online (Sandbox Code Playgroud)
Common.java
public class Common
{
OnSelectedListener mCallback;
public interface OnSelectedListener
{
public void getFailureDialog();
}
public void myRecord(String email)
{
mCallback.getFailureDialog(); //null pointer exception here
}
}
Run Code Online (Sandbox Code Playgroud)
MainActivity.java
public class MainActivity …Run Code Online (Sandbox Code Playgroud) 我通过传递用户名和密码进行基本身份验证,然后使用BasicNameValuePair发送post params来获取服务的响应.
我的方法:
public StringBuilder callServiceHttpPost(String userName, String password, String type)
{
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(WEBSERVICE + type);
HttpResponse response = null;
StringBuilder total = new StringBuilder();
try {
URL url = new URL(WEBSERVICE + type);
/*String base64EncodedCredentials = Base64.encodeToString((userName
+ ":" + password).getBytes(), Base64.URL_SAFE
| Base64.NO_WRAP);*/
String base64EncodedCredentials = "Basic " + Base64.encodeToString(
(userName + ":" + password).getBytes(),
Base64.NO_WRAP);
httppost.setHeader("Authorization", base64EncodedCredentials);
// Add …Run Code Online (Sandbox Code Playgroud) 我一直在上班时继续学习NoClassDefFoundError.
该代码取自BluetoothLeGatt项目 -
http://developer.android.com/samples/BluetoothLeGatt/project.html
我的代码:
// Device scan callback.
private BluetoothAdapter.LeScanCallback mLeScanCallback =
new BluetoothAdapter.LeScanCallback() { //java.lang.NoClassDefFoundError...
@Override
public void onLeScan(final BluetoothDevice device,
final int rssi, final byte[] scanRecord) {
runOnUiThread(new Runnable() {
@Override
public void run() {
String msg= device.getAddress();
Log.d(TAG,msg);
addItems(msg);
}
});
}
};
Run Code Online (Sandbox Code Playgroud)
有人建议错误是因为我的设备不支持BLE但我想为任何设备摆脱这个错误.因此,如果它不支持BLE功能,则只需跳过此错误,否则继续调用此功能BluetoothAdapter.LeScanCallback.
注意:
见这个我以前SO发布更多的澄清.
将BLE功能检查作为第一行onCreate()并不能阻止崩溃 -
@Override
public void onCreate(Bundle savedInstanceState) {
if (!bleCheck()) {
Toast.makeText(getApplicationContext(), R.string.ble_not_supported,
Toast.LENGTH_SHORT).show();
finish();
}
//Rest of the code
//Call to …Run Code Online (Sandbox Code Playgroud) 我ProgressDialog没有显示 - 它在AsyncTask类BackgroundDataLoad中定义.
DialoguePopup类 -
public class DialoguePopup extends DialogFragment {
public DialoguePopup newInstace()
{
DialoguePopup dialogFragment = new DialoguePopup();
return dialogFragment;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
super.onCreateView(inflater, container, savedInstanceState);
//view related code..
//Calculation logic data load in background
new BackgroundDataLoad().execute();
return view;
}
class BackgroundDataLoad extends AsyncTask<String, String, String>
{
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(getActivity());
pDialog.setMessage("Calculating ...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
}
@Override
protected …Run Code Online (Sandbox Code Playgroud) 在SQL Server(T-SQL)中,我们可以像这里发布的那样:
http://www.sqlrelease.com/allow-only-alphanumeric-characters-in-a-column
如何在PostgreSQL中做同样的事情?
以下没有奏效 -
CREATE OR REPLACE FUNCTION dummy.checkalphanumeric(username character varying(32))
RETURNS integer AS
$BODY$
BEGIN
RETURN (SELECT CASE WHEN regexp_matches(username, '%[^a-zA-Z0-9]%') >
false THEN false ELSE true END);
END; $BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
ALTER FUNCTION dummy.checkalphanumeric(username character varying(32))
OWNER TO postgres;
Run Code Online (Sandbox Code Playgroud)
和ALTER查询 -
ALTER TABLE dummy.provisioning_user ADD CONSTRAINT
CK_provisioning_user CHECK (dummycheckalphanumeric(username) = 1)
Run Code Online (Sandbox Code Playgroud) 我有像
1) "CAP07560"
2) "CAP41060"
3) "CAP43500"
4) "CAP22390"
Run Code Online (Sandbox Code Playgroud)
我想"CAP"先从字符串中删除文本,然后再为剩余的字符串删除最后的“ 0”,并在字符串的开头删除所有零。
所以我的输出将是:
1) "756"
2) "4106"
3) "4350"
4) "2239"
Run Code Online (Sandbox Code Playgroud)
我尝试了以下-
public class RegexTest {
public static void main(String[] args) {
// drop the last "0" and then drop any
// zeros at the start of the remaining number.
String str = "CAP07560";
String pattern = "^CAP[ 0]*|( |(?<!\\d))*$";
str = str.replaceAll(pattern, "");
System.out.println(str);
}
}
Run Code Online (Sandbox Code Playgroud)
我的输出: 7560
所以我的输出是,7560但应该是756。