我在用户控制器中获得了这些操作
class UsersController < ApplicationController
def index #default action
...
end
def new #default action
...
end
def another_new
...
end
def create
...
end
def another_create
...
end
end
Run Code Online (Sandbox Code Playgroud)
我希望能够通过
/users/another_new某种链接:method => :another_create
进行调用/users/another_new
我得到了以下config/routes.rb
get '/users/another_new' :to => 'users#another_new'
resources :users
Run Code Online (Sandbox Code Playgroud)
我的问题是,如果这是添加的正确方法get以及我如何添加another_create方法.
我正在使用用户对象填充我的微调器,以便稍后使用用户ID工作,但用户列表的显示显示我猜对象的地址.
所以我的问题是如何只显示对象的一个属性,在用户名的情况下,但仍然用整个对象填充微调器
User user1 = new User("user1",24);
User user2 = new User("user2",26);
// Creating adapter for spinner
List<User> users = new ArrayList<User>();
users.add(user1);
users.add(user2);
ArrayAdapter<User> dataAdapter = new ArrayAdapter<User>(this,
android.R.layout.simple_spinner_item, users);
// Drop down layout style - list view
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
Spinner _EmpSpinner = null;
_EmpSpinner = (Spinner) findViewById(R.id.EmployeesSpinner);
// attaching data adapter to spinner
_EmpSpinner.setAdapter(dataAdapter);
Run Code Online (Sandbox Code Playgroud)

我正在使用列表适配器来显示不同的商店,当有人选择商店时,它会将他们带到一个新活动,在那里他们可以将商店添加到该屏幕上的收藏夹.
该调用上有一个Back按钮finish();,可以通过listview返回到屏幕.
现在的问题是listview没有更新(即没有显示商店已经添加到收藏夹).我尝试了这段代码,但没有运气:
@Override
public void onResume() {
super.onResume();
list.setAdapter(null);
updateMyList();
adapter=new LazyAdapter(this, ((String[])names.toArray(new String[0])),
((String[])status.toArray(new String[0])));
list.setAdapter(adapter);
}
Run Code Online (Sandbox Code Playgroud)
updateMyList() 调用服务器API并更新名称和状态数组.
使用此代码,列表并未真正更新...
我环顾四周寻找类似的问题但找不到与之相符的东西.
我正在尝试扩展内置的JSONObject以添加一些功能,如下所示:
public class MyJSONObject extends JSONObject {
// Easily return an integer from a JSONObject, handling when the value is null.
//
public Integer getIntegerUnlessNull(String key) throws JSONException {
String key_value = this.getString (key);
if ( key_value.equals("null") ) {
return null;
} else {
return Integer.parseInt( key_value );
}
}
}
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试投射它时,我收到一个java.lang.ClassCastException错误:
private JSONArray jsonClients;
MyJSONObject clientJSONRecord;
clientJSONRecord = (MyJSONObject) jsonClients.getJSONObject(0);
Run Code Online (Sandbox Code Playgroud)
完整的错误消息是:
java.lang.ClassCastException: org.json.JSONObject cannot be cast to com.insightemissions.trak.extensions.MyJSONObject
Run Code Online (Sandbox Code Playgroud)
有帮助吗?
干杯,
J.P
我使用Intent MediaStore.ACTION_VIDEO_CAPTURE视频录制方法.
默认情况下,录制的视频存储为.3gp文件.我想录制视频并将其存储为.mp4文件.
这可能吗?.
由于超级灵活和方便,我一直在使用很多Perl哈希.例如,在Perl中我可以执行以下操作:
$hash{AREA_CODE}->{PHONE}->{STREET_ADDR}
Run Code Online (Sandbox Code Playgroud)
我想知道如何用Java完成同样的事情,我想它与HashMap有关?
谢谢,
我在Beanstalk中有我的代码仓库.如何将代码从Beanstalk移动到Github?
如何抑制db:load:schema的输出?运行
bundle exec rake db:schema:load
Run Code Online (Sandbox Code Playgroud)
用-s,-q或甚至VERBOSE=false选项使得在输出没有差别; 我不想看的相同的"create_table ... add_index ..."垃圾出现了.我从自定义Rake任务中调用它,我不希望用户每次都看到所有这些.
更新:
我使用@Deefour的一些指导解决了这个问题:
system "bundle exec rake db:schema:load -s RAILS_ENV=#{Rails.env} >NUL"
Run Code Online (Sandbox Code Playgroud)
>NUL适用于Windows机器,基于Unix可以使用> /dev/null.
而不是
Rake::Task['db:schema:load'].invoke
Run Code Online (Sandbox Code Playgroud)
正如我在自定义任务中所做的那样.请注意,此解决方案特定于Windows计算机.对于基于Unix的机器,我想你应该能够使用下面接受的解决方案.
我正在使用pdfkit(在引擎盖下使用wkhtmltopdf)在我的rails应用程序中生成PDF.按照这里的指南,我已经得到它主要用于PDF的基本情况.在尝试生成包含大量页面的PDF时,我现在遇到了一个问题,这些页面也有页眉/页脚.尝试生成PDF时,我在控制台中从wkhtmltopdf看到的错误是:
QEventDispatcherUNIXPrivate(): Unable to create thread pipe: Too many open files
QEventDispatcherUNIXPrivate(): Can not continue without a thread pipe
Run Code Online (Sandbox Code Playgroud)
可用于重新创建错误的html的最小示例:
<!-- content of pdf_header_url is the character "h" -->
<meta content="<%= pdf_header_url %>" name="pdfkit-header-html"/>
<!-- content of pdf_footer_url is the character "f" -->
<meta content="<%= pdf_footer_url %>" name="pdfkit-footer_html"/>
<% [*1..3].each do |j|%>
<h1><%= j %></h1>
<ul>
<% [*1..1000].each do |i|%>
<li><%= i %></li>
<% end %>
</ul>
<% end %>
Run Code Online (Sandbox Code Playgroud)
请注意,删除页眉/页脚标记允许pdf呈现正常.
生成PDF的实际ruby代码是:
def view_report
html = …Run Code Online (Sandbox Code Playgroud) 是否有可能在错误消息中validate_uniqueness_of显示id已包含我正在检查唯一性的字段的记录?