我收到一个错误:
undefined method `user_path' for #<#<Class:0x007fd1f223ead0>:0x007fd1f2241af0>
Run Code Online (Sandbox Code Playgroud)
当我正在尝试编辑学生时.我真的不理解"user_path"方法警报,因为我从未在视图中写过这个.(学生不是模特)我没有使用rails g scaffold来生成它.
谢谢
在我的StudentsController中:
def edit
@student = User.find(params[:id])
end
Run Code Online (Sandbox Code Playgroud)
在视图中(edit.html.erb):
<%= form_for(@student) do |f| %> ...
Run Code Online (Sandbox Code Playgroud)
在routes.rb中:
resources :students
Run Code Online (Sandbox Code Playgroud) 我有一个静态方法的类:这个类包装了对Twitter API的调用
在第二节课中,我有一些商业逻辑.
由于包装类中某些方法的异步行为,我很难设计通信.这就是我所做的:
APIManager.swift
public class APIManager {
class func getPermission(callback : () -> Void) {
let accountStore = ACAccountStore()
let accountType =
ACAccountStore().accountTypeWithAccountTypeIdentifier(ACAccountTypeIdentifierTwitter)
let callbackRequestAccess = { (granted: Bool, error: NSError!) -> Void in
...
if(granted) {
callback()
}
}
accountStore.requestAccessToAccountsWithType(setAccountType,
options: nil, completion: callbackRequestAccess)
}
}
Run Code Online (Sandbox Code Playgroud)
Welcome.swift
public class Welcome {
public func checkPermission() {
APIManager.getPermission(getTweet)
}
public func getTweet() {
...
}
}
Run Code Online (Sandbox Code Playgroud)
我不确定这个设计是否合适.我不想在这些类之间建立强大的联系,这就是我使用回调的原因.
这是经典设计吗?而且,我觉得这种行为不容易测试吗?
在一个集合中,我存储了这种文档:
{
"_id" : ObjectId("55e8a5cba21b9e051eb448d1"),
"created_at" : "2015-01-01T00:00:24Z",
...
}
Run Code Online (Sandbox Code Playgroud)
我想将created_at的类型从String更改为ISODate以获取
{
"_id" : ObjectId("55e8a5cba21b9e051eb448d1"),
"created_at" : ISODate("2015-01-01T00:00:24Z)",
...
}
Run Code Online (Sandbox Code Playgroud)
我找到了一个解决方案:遍历所有集合
db.trial.find().forEach(
function(doc) {
doc.created_at = ISODate(doc.created_at);
db.events_January_watch.save(doc);
}
);
Run Code Online (Sandbox Code Playgroud)
但这是非常缓慢和低效的,我宁愿使用聚合管道+ $ out
这是我试过的:
db.trial.aggregate(
[
{
$project: {
created_at : "$created_at",
created_at_iso: {$add: ISODate("$created_at_noTime") }
}
},
{
$out: "trialIso"
}
],
{
allowDiskUse: true
}
);
Run Code Online (Sandbox Code Playgroud)
抛出:E QUERY错误:ISO日期无效
我不明白为什么
ISODate("2015-01-01T00:00:24Z")
Run Code Online (Sandbox Code Playgroud)
在mongo shell中完美运行.
(这是因为,$ created_at变量尚未在聚合管道中设置吗?)
我正在重构我的应用程序,以确保它符合MVC.我想拆分控制器(扩展UIController的MyController)和视图(扩展UIView的HomeView)我在myController中设置视图
self.view = [[HomeView alloc] init];
Run Code Online (Sandbox Code Playgroud)
当我按下UIButton时,在视图中调用一个方法,在这个方法中我想从控制器调用一个方法.
在我看来
[zenModeBtn addTarget:self action:@selector(touchZenMode:) forControlEvents:UIControlEventTouchDown];
Run Code Online (Sandbox Code Playgroud)
...
- (void) touchZenMode:(id) sender {
[myController playZenMode];
}
Run Code Online (Sandbox Code Playgroud)
但是在视图中引用控制器实际上是一种不好的做法不是吗?
编辑:
所以在我的UIViewController中我做了这个:
- (id) init {
HomeView* myHomeView = [[HomeView alloc] init];
[myHomeView.arcadeModeBtn addTarget:self action:@selector(touchArcadeMode) forControlEvents:UIControlEventTouchUpInside];
self.view = myHomeView;
return self;
}
Run Code Online (Sandbox Code Playgroud)
那是对的吗 ?
在这段代码中
String a = "notANumber";
Integer b = Integer.parseInt(a);
Run Code Online (Sandbox Code Playgroud)
parseInt抛出NumberFormatException异常后需要try/catch .
在我之前的Eclipse版本中,我曾经得到一个警告告诉我需要一个try/catch但是我无法弄清楚如何在我当前版本的Eclipse上启用它,这是
Eclipse Java EE IDE for Web Developers.
Version: Kepler Service Release 1
Run Code Online (Sandbox Code Playgroud) 任务模型只有一个字段:标题.
我已经创建了一个表单,用一个字段添加一个新任务:title
但是在create方法中,我们可以看到标题被"test"填充
但在查询中,我们可以看到"无"......任何想法?
谢谢
Started POST "/tasks" for 127.0.0.1 at 2013-01-03 13:16:44 -0500
Processing by TasksController#create as HTML
Parameters: {"utf8"=>"?", "authenticity_token"=>"iWaK1QX6VCyeUCueLrRNErJEtdm/ZNxg4d3LU0vKjnY=", "task"=>{"title"
=>"test"}, "commit"=>"Add a new task "}
(0.1ms) begin transaction
SQL (0.9ms) INSERT INTO "tasks" ("created_at", "title", "updated_at") VALUES (?, ?, ?) [["created_at", Thu, 03 Jan 2013 18:16:44 UTC +00:00], ["title", nil], ["updated_at", Thu, 03 Jan 2013 18:16:44 UTC +00:00]]
(0.8ms) commit transaction
Redirected to http://0.0.0.0:3000/tasks
Completed 302 Found in 8ms (ActiveRecord: 1.8ms)
Run Code Online (Sandbox Code Playgroud)
这是创建方法
def create
@task = …Run Code Online (Sandbox Code Playgroud) 我有一个关于Java中ArrayList的clone()方法的问题.
ArrayList<HeavyOjbect> original = new ArrayList<HeavyOjbect>();
original.add(new HeavyOjbect(0));
original.add(new HeavyOjbect(1));
original.add(new HeavyOjbect(2));
ArrayList<Integer> copy = original;
copy.remove(0);
Run Code Online (Sandbox Code Playgroud)
原创 - > [HeavyOjbect1,HeavyOjbect2]
copy - > [HeavyOjbect1,HeavyOjbect2]
现在使用clone()方法
ArrayList<HeavyOjbect> original = new ArrayList<HeavyOjbect>();
original.add(new HeavyOjbect(0));
original.add(new HeavyOjbect(1));
original.add(new HeavyOjbect(2));
ArrayList<Integer> copy = (ArrayList<HeavyOjbect>) original.clone();
copy.remove(0);
Run Code Online (Sandbox Code Playgroud)
原始 - > [HeavyOjbect0,HeavyOjbect1,HeavyOjbect2]
copy - > [HeavyOjbect1,HeavyOjbect2]
对 ?
但我无法弄清楚克隆的作用.它是否克隆每个HeavyObject?我的意思是如果克隆1000倍我的ArrayList,内存是否会爆炸?
编辑:所以克隆
new HeavyOjbect(0) -> @10
new HeavyOjbect(1) -> @20
new HeavyOjbect(1) -> @30
original(ref1 to @10, ref1 to @20, ref1 to @30)
copy(ref2 to @10, ref2 …Run Code Online (Sandbox Code Playgroud) ios ×2
java ×2
arraylist ×1
asynchronous ×1
clone ×1
cocoa ×1
cocoa-touch ×1
crud ×1
eclipse ×1
mongodb ×1
performance ×1
ruby ×1
swift ×1
try-catch ×1