我很难创建干净的可维护HTML/CSS代码.是否有可以帮助我使用最佳实践的编辑器,书籍或网页.
这是一些例子:
div和类的命名:您可能拥有一个包含用户配置文件的区域.你会如何命名id和类?(#author_profile,.username,.userBirthday等)
标签或div:很多时候我很困惑何时创建自己的div或使用带有id/class的标签.有什么好例子吗?
定位:99%的时间我在元素上设置固定宽度并使用float:left/right.有关使CSS定位更易于访问的任何提示.我已经尝试了很多CSS框架,但这对我没有用.总是以深层嵌套的div和很多类结束.
我想检查一下我的旧网站上是否存在一些URL,并收集返回404的URL.
@paintings = Painting.find(:all)
@paintings.each do |painting|
open("http://www.mydomain.com/" + painting.user.username.downcase + "/" + painting.permalink)
rescue OpenURI::HTTPError
@failure += painting.permalink
else
@success += painting.permalink
end
end
Run Code Online (Sandbox Code Playgroud)
嗯,我无法通过救援方法来获取错误
syntax error, unexpected kRESCUE, expecting kEND
rescue OpenURI::HTTPError
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
我需要转换一些字符串,然后拉出两个第一个整数,例如:
unkowntext60moreunknowntext25something
至:
@width = 60
@height = 25
Run Code Online (Sandbox Code Playgroud)
如果我这样做string.to_i,我得到第一个整数:,60.我无法弄清楚我是如何得到第二个整数,25.任何想法?
我有一个ajax方法,用于渲染用户的@collection.此代码来自用户部分.现在我需要做的是为每个第三个对象在3 li标签周围包裹一个ul标签.我如何使用HAML执行此操作?我不能只将%ul标记添加到"when 1" - 因为HAML在渲染该对象时关闭标记.
-case user_counter + 1
-when 1
%li.first
@user.login
-when 2
%li
@uer.login
-when 3
%li.last
@user.login
Run Code Online (Sandbox Code Playgroud)
这是我正在寻找的结果:
<ul>
<li>user1</li>
<li>user2</li>
<li>user3</li>
</ul>
<ul>
<li>user4</li>
<li>user5</li>
<li>user6</li>
</ul>
Run Code Online (Sandbox Code Playgroud)
等等
我正在使用searchlogic来搜索一些画作.每幅画都属于一个类别.我想要做的是在我的搜索表单中添加多个复选框,以便用户可以标记多个类别.(与or一起使用)这可能与searchlogic一起使用吗?我正在寻找的查询是这样的:
SELECT * FROM paintings WHERE category LIKE "white" OR category LIKE "red"...
f.check_box :category (white)
f.check_box :category (black)
f.check_box :category (red)
f.check_box :category (green)
Run Code Online (Sandbox Code Playgroud)
等等
我正在使用IMAP从gmail接收一些电子邮件,然后使用新的Rails 3 ActionMailer接收方法解析它们.
raw_email = imap.uid_fetch(uid, ['RFC822']).first.attr['RFC822']
email = UserMailer.receive(raw_email)
Run Code Online (Sandbox Code Playgroud)
电子邮件现在是一个Mail :: Message Class,并且:,from和:subject工作正常.但是我无法弄清楚如何从身体中获取纯文本.在Rails 3之前,我可以使用tmail_body_extractors插件来获取普通的主体.
你会如何使用Rails 3做到这一点?
Jakobinsky:email.body.raw_source离我更近了仍然给了我很多垃圾.
"--001636310325efcc88049508323d\r \nConContent-Type:text/plain; charset = ISO-8859-1\r \nContent-Transfer-Encoding:quoted-printable\r \n\r \n这是一些正文内容\ r \n\r \n - = 20\r \nVenlig Hilsen\r \nAsbj = F8rn Morell\r \n\r \n - 001636310325efcc88049508323d\r \n内容类型:text/html; charset = ISO-8859-1\r \nContent-Transfer-Encoding:quoted-printable\r \n\r \naf 邮件
-
Venlig Hilsen Asbj
= F8rn Morell
\ r \n\r \n - 001636310325efcc88049508323d--"
我应该滚动自己的帮助器来清理raw_source还是已经有方法,宝石或帮助器?
我写了一个小的基准测试类来测试我的代码进行开发.目前我必须将Class添加到每个方法的开头和结尾.是否可以预先添加,动态附加,以便我不必弄乱我的代码?
class ApplicationController
before_filter :init_perf
after_filter :write_perf_results_to_log!
def init_perf
@perf ||= Perf.new
end
def write_perf_results_to_log!
@perf.results
end
end
class Products < ApplicationsController
def foo
@perf.log(__methond__.to_s)
caculation = 5 *4
@perf.write!
end
def bar
@perf.log(__methond__.to_s)
caculation = 1 / 5
@perf.write!
end
end
Run Code Online (Sandbox Code Playgroud)
这是Perf类.它位于services文件夹中.
class Perf
def initialize
@results = []
end
def log(note)
@start = Time.now
@note = note
end
def write!
if @results.find {|h| h[:note] == @note } # Update :sec method exists in results
@results.select { |h| h["note"] …Run Code Online (Sandbox Code Playgroud) 可能重复:
如何获取调用方法的名称?
在下面的示例中,如何告诉foo使用哪种方法?
class Example
def initialize
end
def foo
puts "Hello World"
end
def bar
foo
end
def cats
bar
end
end
Run Code Online (Sandbox Code Playgroud)
Example.new.cats打印栏.我想要获得整个callstack.例如猫 - >吧 - > foo
更新:
这有效:把来电者[0..1]
Hello World
(irb):11:in `bar'
(irb):15:in `cats'
Run Code Online (Sandbox Code Playgroud) 如何验证字段 - 使其至少包含3个字母字符.
Valid:
Something, Foobar 111.
Invalid:
.......
Run Code Online (Sandbox Code Playgroud)
最好的祝福.AsbjørnMorell