#2 楼 @jzlikewei 把图片名字 hash 或许可以
直接 grape 吧,如果要在上面写 api 文档就加上 sinatra(web 页面)和 SwaggerUI(api 的 ui 界面)
如果是你带着做,我觉得就合格了。
哈哈,以前是 wordpress,很久的事了。你再去看他的论坛。
#6 楼 @chairy11 你的 blog 挂掉啦!!! http://topit.me/
ruby 的相关 gem 有 curb(curl) 适合抓取 json 通信类数据,mechanize 适合抓取少 js 和 iframe 类页面,watir 貌似只能用来做测试,直接模拟浏览器,但是速度可想而知。phantomjs 据说很不错,没用过。
rails s 应该就是 webrick。楼主真要这么干?还是换 thin 或者 puma 吧,或者省事点 apache+passenger
浏览器自带的就够啦。
nginx+passenger+mysql 的:https://ruby-china.org/topics/20216 apache+php+mysql+passenger 的:http://flowerwrong.iteye.com/blog/2105093
补充 watir 版本
# -*- coding: utf-8 -*-
require 'watir-webdriver'
b = Watir::Browser.new
USER_NAME = "[email protected]"
PASS = "xxx"
login_url = "https://ruby-china.org/account/sign_in"
b.goto login_url
b.text_field(:name => 'user[login]').set USER_NAME
b.text_field(:name => 'user[password]').set PASS
b.button(:name => 'commit').click
puts b.text
#1 楼 @saiga 我改了下,先 get 取得 token,然后 post,可是还是不行
require 'curb'
require 'nokogiri'
USER_NAME = "[email protected]"
PASS = "xxx"
login_url = "https://ruby-china.org/account/sign_in"
c = Curl::Easy.new
c.url = login_url
c.http_get
doc = Nokogiri::HTML(c.body_str)
csrf_token = doc.xpath("//meta[@name='csrf-token']/@content")[0].value.strip
c.url = login_url
c.enable_cookies = true
c.cookiejar = "cookies.txt"
user = {
"user\[login\]" => USER_NAME,
"user\[password\]" => PASS,
"authenticity_token" => csrf_token,
"user\[remember_me\]" => 0,
"utf8" => "✓",
"commit" => "登陆"
}
c.http_post(c.url,user)
puts csrf_token
puts "---" * 20
puts c.header_str
打印结果
flowerwrong@flowerwrong:~/dev/ruby/mechanize$ ruby ruby_china.rb
2O85a3ZBPvdTyo3XQNvvvVlg57VLQ/+vhm3ktyIXXbE=
------------------------------------------------------------
HTTP/1.1 200 OK
Server: nginx/1.6.0
Date: Tue, 19 Aug 2014 10:09:45 GMT
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Strict-Transport-Security: max-age=31536000
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
X-Content-Type-Options: nosniff
ETag: "c889b4d41d8ddd454f2d022cdc8ef457"
Cache-Control: max-age=0, private, must-revalidate
X-Request-Id: ffce7524-a903-4844-943e-0b54b872ccfc
X-Runtime: 0.042324
RAILS_ENV=production rake db:migrate 默认是 test+development
js 或者 ruby 的可以操作 html 的 gem,遍历一次,替换吧。
#5 楼 @blacktulip 哈哈
@billy 印象最深的就是 activerecord,不用声明对象属性。还没写过,楼主主要用在那些地方?
我怎么觉得 ruby 东西太少呢?
#10 楼 @chairy11 update 里面的我没写,但是除了 content 字段保存 html 内容外,还有一个 markdown 字段保存 markdown 原格式。所以
def update
@article = Article.find(params[:id])
markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, autolink: true, tables: true, fenced_code_blocks: true)
html_content = markdown.render(article_params[:markdown])
@article.content = html_content
@article.markdown = article_params[:markdown]
respond_to do |format|
if @article.save
format.html { redirect_to @article, notice: 'Article was successfully updated.' }
format.json { render :show, status: :ok, location: @article }
else
format.html { render :edit }
format.json { render json: @article.errors, status: :unprocessable_entity }
end
end
end
就 ok 了。喔,对了,markdown 实例可以用单例模式。这里就省了。
我只用了 redcarpet 一个 gem,http://rubydoc.info/gems/redcarpet/3.1.2/frames demo:https://github.com/FlowerWrong/markdowndemo