我有一个Android应用程序,其中的首选项以XML格式声明,并加载了addPreferencesFromResource
.用户可以打开首选项,单击每个项目并编辑它们,所有工作.
我有一个偏好是:
<ListPreference android:key="abc"
android:title="@string/abc"
android:summary="@string/cde"
android:persistent="true"/>
Run Code Online (Sandbox Code Playgroud)
如何自动向用户显示首选项对话框(用户无需转到首选项屏幕并单击它?).
我试过( (android.preference.DialogPreference) prefMgr.findPreference( "abc" )).showDialog(null)
,但是说这是一种受保护的方法......?从我的主要活动(即a PreferenceActivity
)中调用它,这就是它显然无法工作的原因.但是怎么回事?
编辑
我刚刚发现两个线程(1和2)的想法findViewById
用于访问首选项,但没有成功.它总是返回null(对我来说也是如此).
看起来似乎没有可能从代码中做到这一点.
我正在使用Rails的默认I18n模块在视图中翻译我的字符串.
<%= t("registration.heading") %>
Run Code Online (Sandbox Code Playgroud)
现在,当我在注册视图中时,我的所有字符串都以registration
.我总是要写
<%= t("registration.heading.notice") %>
// or
<%= t(:heading, :scope => :registration) %>
Run Code Online (Sandbox Code Playgroud)
定义该文件的默认范围(甚至可能在控制器中)会很好,因此调用会t
自动添加已定义的范围
// controller
set_i18n_default_scope :registration
// view
<%= t(:heading) %>
// --> looks in "registration.heading"
Run Code Online (Sandbox Code Playgroud)
这可能吗?
我正在使用带有"经典"风格的Apache和Phusion-Passenger的Sinatra:
# config.ru
require 'sinatra'
configure do
....
end
require './app'
run Sinatra::Application
Run Code Online (Sandbox Code Playgroud)
我想定义一些东西.在配置块内部或外部定义它有什么区别?
# config.ru
require 'sinatra'
# A) Defining logger here
rack = File.new("logs/rack.log", "a+")
use Rack::CommonLogger, rack
# B) Global variables here
LOGGER = Logger.new(...)
# C) Gem configuration here
DataMapper::Property::Boolean.allow_nil(false)
configure do
# A) Or defining logger here?
rack = File.new("logs/rack.log", "a+")
use Rack::CommonLogger, rack
# B) Or global variables here?
LOGGER = Logger.new(...)
# C) Or gem configuration here?
DataMapper::Property::Boolean.allow_nil(false)
....
end
require './app'
run …
Run Code Online (Sandbox Code Playgroud) 我正在尝试执行以下操作:
module ApplicationHelper
class PModuleHelper
include ActionView::Helpers::TagHelper
def heading(head = "", &block)
content = block_given? ? capture(&block) : head.to_s
content_tag :h3, content, :class => :module_header
end
end
def getmh
PModuleHelper.new
end
end
Run Code Online (Sandbox Code Playgroud)
为方法heading
或块提供字符串(或符号).
在视图中:
<% mh = getmh %>
<%= mh.heading :bla %> // WORKS
<%= mh.heading do %> // FAILS
test 123
<% end %>
Run Code Online (Sandbox Code Playgroud)
(注意这getmh
只是为了这个例子,PModuleHelper
我的应用程序中的一些其他进程返回,所以不需要对此进行评论或建议制作heading
正常的辅助方法,而不是类方法)
不幸的是我总是收到以下错误:
wrong number of arguments (0 for 1)
Run Code Online (Sandbox Code Playgroud)
与亚麻布的capture(&block)
电话.
如何使用capture
自己的助手类?
可以说我有一个嵌套哈希:
h = { 'one' =>
{'two' =>
{'three' => 'a'}
}
}
Run Code Online (Sandbox Code Playgroud)
我可以这样改变它:
h['one']['two']['three'] = 'b'
Run Code Online (Sandbox Code Playgroud)
如何使用变量作为键来更改嵌套值?
假设我有以下变量:
key = "one.two.three"
Run Code Online (Sandbox Code Playgroud)
要动态访问它,我使用以下内容:
key.split('.').inject(h,:[])
Run Code Online (Sandbox Code Playgroud)
但是当然设置它不起作用:
key.split('.').inject(h,:[]) = 'b' # fails
Run Code Online (Sandbox Code Playgroud)
那么如何动态设置嵌套哈希的值呢?
让我们使用这些类:
class User < ActiveRecord::Base
has_many :project_participations
has_many :projects, through: :project_participations, inverse_of: :users
end
class ProjectParticipation < ActiveRecord::Base
belongs_to :user
belongs_to :project
enum role: { member: 0, manager: 1 }
end
class Project < ActiveRecord::Base
has_many :project_participations
has_many :users, through: :project_participations, inverse_of: :projects
end
Run Code Online (Sandbox Code Playgroud)
A user
可以参与许多projects
角色扮演a member
或a manager
.调用连接模型ProjectParticipation
.
我现在在使用未保存对象上的关联时遇到问题.以下命令的工作方式与我认为应该有效相同:
# first example
u = User.new
p = Project.new
u.projects << p
u.projects
=> #<ActiveRecord::Associations::CollectionProxy [#<Project id: nil>]>
u.project_participations
=> #<ActiveRecord::Associations::CollectionProxy [#<ProjectParticipation id: nil, …
Run Code Online (Sandbox Code Playgroud) 我有以下偏好:
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<RingtonePreference
android:showDefault="true"
android:showSilent="true"
android:title="@string/feed_alert_ringtone"
android:ringtoneType="ringtone|notification|alarm|all"
android:key="alertringtone"
android:persistent="false">
</RingtonePreference>
</PreferenceScreen>
Run Code Online (Sandbox Code Playgroud)
当用户更改此首选项时,我手动将Uri保存到数据库:
public boolean onPreferenceChange(Preference pref, Object change) {
String ringtone = change.toString();
// save it to a db
...
return true;
}
Run Code Online (Sandbox Code Playgroud)
我的问题是,当用户关闭然后返回时PreferenceScreen
,默认的值RingtonePreference
始终是Silence
.当然,我必须手动设置值.
在我的尝试中尝试过这个PreferenceActivity
:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.settings); // the XML above
String database_ringtone = ... // get the string saved above from db
// and according to some parameters passed
// to the intent
Preference ringtone …
Run Code Online (Sandbox Code Playgroud) 来自apache2的唯一功能是我无法存档:让用户使用密码数据库(htpasswd
)并允许访问不同的文件/文件夹/虚拟服务器.
我启用的基本http auth工作原理:
location ~ ^/a/ {
# should allow access for user1, user2
auth_basic "Restricted";
auth_basic_user_file /etc/nginx/auth/file_a;
}
location ~ ^/b/ {
# should allow access for user2, user3
auth_basic "Restricted";
auth_basic_user_file /etc/nginx/auth/file_b;
}
Run Code Online (Sandbox Code Playgroud)
如果我有user1,user2 in file_a
和user2,user3 in file_b
,这可行,但是当我更改user2的密码时我必须更新这两个文件(所有位置的密码应该相同).由于我将拥有> 15个具有不同访问权限和> 10个用户的不同位置,因此这并不容易处理.(我喜欢精细的访问权限!)
使用Apache,我为每个位置定义了不同的组,并且需要正确的组.更改访问权限就像向组添加/删除用户一样简单.
是否有类似的东西或如何使用nginx轻松处理这种情况?
我正试图通过cli运行这个简单的守护进程
function doTask(){
echo 'mytest';
}
// Include PEAR's Daemon Class
require_once "/usr/share/php/System/Daemon.php";
// Bare minimum setup
System_Daemon::setOption("appName", "mydaemonname2");
try{
// Spawn Deamon!
System_Daemon::start();
// Your PHP Here!
while (true) {
doTask();
}
// Stop daemon!
System_Daemon::stop();
}
catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
notice: Starting mydaemonname daemon, output in: '/var/log/mydaemonname.log'
[Feb 08 12:17:23] warning: [PHP Error] file_put_contents(/var/log/mydaemonname.log): failed to open stream: Permission denied
Run Code Online (Sandbox Code Playgroud)
在我的本地主机和我的开发服务器中.
如果我尝试粗略创建并将chmod 777文件权限设置为/var/log/mydaemonname.log,我会收到此其他错误
[Feb 08 12:30:31] notice: Starting mydaemonname daemon, output …
Run Code Online (Sandbox Code Playgroud) 我正在尝试上传我的 Rails 应用程序:
bin/cap production deploy
Run Code Online (Sandbox Code Playgroud)
但部署失败并显示此错误消息:
You have requested:
capistrano ~> 3.3.0
The bundle currently has capistrano locked at 3.7.1.
Try running `bundle update capistrano`
If you are updating multiple gems in your Gemfile at once,
try passing them all to `bundle update`
Run Code Online (Sandbox Code Playgroud)
我试图通过运行来解决这个问题:
bundle update capistrano
Run Code Online (Sandbox Code Playgroud)
但这并没有解决它。
我不明白的是我没有看到我的应用程序“要求 capistrano 3.3.0”。在我的 Gemfile 中,我将 Capistrano 设置为 3.7 版。
除了 capistrano gem 外,我还在使用:
gem capistrano-rails, '~> 1.2'
gem capistrano3-delayed-job, '~> 1.3'
gem capistrano-figaro-yml
Run Code Online (Sandbox Code Playgroud)
我的 Gemfile 位于:
https://github.com/acandael/personalsite/blob/master/Gemfile
有人知道我如何解决这个 Capistrano 版本问题吗?
感谢您的帮助, …
当我运行页面时它会抛出此错误,但我不知道为什么:
警告: mysqli_fetch_array()期望参数1为mysqli_result,第234行的C:\ wamp\www\SAMS\record.php中给出布尔值
这是我的查询:
$data = "SELECT *, (SELECT SUM(studAtt_endTime - studAtt_startTime) FROM studentAttendance WHERE studAtt_status='0')
FROM studentAttendance INNER JOIN student ON studentAttendance.student_stud_matric=student.stud_matric
INNER JOIN course ON studentAttendance.course_course_code=course.course_code
WHERE WHERE studentAttendance.course_course_code LIKE '%$_GET[course]%' GROUP BY student_stud_matric;";
Run Code Online (Sandbox Code Playgroud) 像这样设置哈希的默认值:
hash = Hash.new { |hsh, key| hsh[key] = {} }
Run Code Online (Sandbox Code Playgroud)
将为未知密钥创建(并分配)新哈希,但将返回nil
创建哈希的未知密钥:
hash[:unkown_key] #=> {}
hash[:unkown_key][:nested_unknown] #=> nil
Run Code Online (Sandbox Code Playgroud)
我可以让它适用于第二级,如下所示:
hash = Hash.new do |hsh, key|
hsh[key] = Hash.new { |nest_hsh, nest_key| nest_hsh[nest_key] = {} }
end
Run Code Online (Sandbox Code Playgroud)
但是,它在第三级不起作用:
hash[:unkown_key][:nested_unknown] #=> {}
hash[:unkown_key][:nested_unknown][:third_level] #=> nil
Run Code Online (Sandbox Code Playgroud)
如何让它在任意级别工作?
hash[:unkown_key][:nested_unknown][:third_level][...][:nth_level] #=> {}
Run Code Online (Sandbox Code Playgroud) ruby ×3
android ×2
hash ×2
php ×2
activerecord ×1
capistrano ×1
capture ×1
css ×1
daemon ×1
html ×1
mysql ×1
mysqli ×1
nested ×1
nginx ×1
passenger ×1
sinatra ×1
textarea ×1
view-helpers ×1
whitespace ×1