新的Rails ...我已经创建了一个帮助器来格式化种族名称及其日期.:id => "current-race"如果存在条件,我需要通过(基本上如果事件正在发生).我怎么能这样做?
def formatted_race_dates(race)
link_to (race.homepage) do
raw("<strong>#{race.name}</strong> <em>#{race_dates_as_string(race)}</em>")
end
end
Run Code Online (Sandbox Code Playgroud)
现在当race.start_date < Date.today && race.end_date > Date.today我想添加id="current-race"链接时.
我通常会设置一个if/else条件并将其格式化为两种方式.但似乎必须有一个我不知道的Ruby技巧来简化某些内容,就像link_to在列表中常见地添加id/class一样?即使没有条件,我也不太确定在哪里/如何添加:id => "current-race".
如此多的Ruby/Rails技巧我不知道......一切都有帮助!
如何轻松地设置博客文章(在 Rails 应用程序中)的格式?至少我想在text显示为 HTML 时保留回车符。我想理想情况下它会允许粗体、斜体和缩进。
我知道CKEditor。我只是担心这可能有点矫枉过正,而且很难快速轻松地实施......
我的Rails应用程序都使用Twitter Bootstrap进行了美化,但我想我不知道如何将Bootstrap的响应行为添加到资产管道中.
目前,当我拉伸窗户时,它不会增长(或收缩,就此而言).
我在以下位置添加了视口元数据<head>:
<meta content='width=device-width, initial-scale=1.0' name='viewport'>
Run Code Online (Sandbox Code Playgroud)
但是,不太确定添加样式表的方式或位置:
<link href="assets/css/bootstrap-responsive.css" rel="stylesheet">
Run Code Online (Sandbox Code Playgroud) ruby-on-rails asset-pipeline responsive-design twitter-bootstrap
试图将类添加到所有输入单元unless的输入内容的type == 'submit'
$('input, textarea') ->
unless $(@).getAttribute('type').val == "submit"
$(@).addClass('form-control')
Run Code Online (Sandbox Code Playgroud)
我的Javascript调试工具包不是很发达......所以不得不破译神秘的错误:
[Error] TypeError: '[object Object]' is not a function (evaluating '$('input, textarea')')
ready (disk_files.js, line 37)
dispatch (jquery.js, line 5096)
handle (jquery.js, line 4767)
dispatchEvent
triggerEvent (turbolinks.js, line 199)
onload (turbolinks.js, line 45)
Run Code Online (Sandbox Code Playgroud) 由于在我们的 Rails 应用程序中删除用户的错误,我试图将另一个用户记录强制转换为旧记录 ID。
$ rails console
> User.find(2)
ActiveRecord::RecordNotFound: Couldn't find User with 'id'=2
> replacer = User.find(5)
=> #<User id: 5, created_at: [omitted for brevity ...] >
replacer.id = 2
=> 2
replacer.save
=> true
> User.find(2)
ActiveRecord::RecordNotFound: Couldn't find User with 'id'=2
> User.find(5)
ActiveRecord::RecordNotFound: Couldn't find User with 'id'=5
> replacer
=> #<User id: 2, created_at: [omitted for brevity ...] >
> replacer.valid?
=> true
Run Code Online (Sandbox Code Playgroud)
这里发生了什么?
小团队.一位同事origin:master误入歧途.他已经重置了他的本地仓库,但不能push -f到Github,因为回购受到保护.
我已经fetch编辑了回购,但没有将他的错误提交合并到我当地master......但是.
我怎么能,假设我可以push -f来源,重置originGithub,以便它反映出他错误之前的状态?
$ git push origin 2860a4c:master
To github.com:example/myproj.git
! [rejected] 2860a4c -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:example/myproj.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
Run Code Online (Sandbox Code Playgroud)
git pull在我可以接受之前,我是否真的需要整合糟糕的提交(与),reset hard 2860a4c然后push -f origin呢? …
为我的 iTerm 字体试用 Powerlevel9k。似乎正在工作,但在一个特定项目中,它添加cherry-or-revert在分支名称之后。
master“问题”存储库中的分支是干净的,没有任何暂存或工作目录中的内容。
这不会发生在其他存储库中~/.oh-my-zsh,例如,甚至其他 Rails 项目。
我错过了什么?
我喜欢通过传递一个值来创建一个自定义类的实例,该值在初始化时将帮助设置它.我已经覆盖了init并且实际上将其更改为:
- (id)initWithValue:(NSInteger *)initialValue;
Run Code Online (Sandbox Code Playgroud)
我想将此值存储在实例化对象的属性中,并使用该值生成将与其关联的UIImage的文件名.
我的问题是如何在Cocoa/Obj-C中最好地解决这个问题.NSInteger是我需要的最佳参数还是NSString会更好?还是有其他设计模式?我不熟悉在这种情况下可以提供帮助的所有创作方法.假设我的类属性是:
@interface MyView : UIView {
UIImage *image;
NSInteger value;
Run Code Online (Sandbox Code Playgroud)
如果我坚持使用NSInteger的作为参数,我可以轻松地分配值给它.但是然后需要从该值生成"image12.png"(假设NSInteger = 12)来设置我的UIImage.像"image"+ initialValue +".png"之类的东西.我相信在Obj-C中详细表达如下:
NSString *myValue = @"image";
[myValue stringByAppendingString:[initialValue stringValue]]; //NSInteger may not respond to stringValue?!?
[myValue stringByAppendingString:@".png"]
Run Code Online (Sandbox Code Playgroud)
这是我对Obj-C的理解破裂的地方.像这样的感觉应该更容易,但我仍然感到困惑.
现在,如果initialValue是一个值为@"12"的NSString,那么它可能是?那么self.value = [initialValue integerValue];
我可以用多个stringByAppendingString调用构建图像.对于其他语言中这么简单的事情来说,这似乎很乏味.
什么是处理这样的事情的最佳方法?
我正在尝试用KVC更新一些属性.这些属性已经合成.
这条线有效:
myObject.value = intValue;
Run Code Online (Sandbox Code Playgroud)
这不起作用:
[self setValue:[NSNumber numberWithInt:intValue] forKey:@"myObject.value"];
Run Code Online (Sandbox Code Playgroud)
并且爆发: 由于未捕获的异常'NSUnknownKeyException'终止应用程序,原因:'[<MyViewController 0xd1cec0> setValue:forUndefinedKey:]:此类与密钥myObject.value不符合密码值编码.
然而,该方法(awakeFromNib)的其他实例还可以对setValue:forKey:calls做出很好的响应.唯一的区别是这个特定的实例是在IB中创建和连接的.
我喜欢HAML,但却遇到了与标签和空格的烦恼.有没有一种简单的方法可以在TextMate中将文件从一个文件转换为另一个文件?
我更喜欢标签,但我看到空间使用了很多...想知道这是否是首选或者如果这是我看到的代码工件发布到网络上了?!?我真的不在乎,虽然对我而言,标签更容易使用...
cocoa ×2
cocoa-touch ×2
objective-c ×2
clearance ×1
coffeescript ×1
formatting ×1
git ×1
github ×1
haml ×1
helpers ×1
html ×1
iterm2 ×1
javascript ×1
jquery ×1
master ×1
oh-my-zsh ×1
textarea ×1
textmate ×1
themes ×1