然后,我想使用Paperclip为每个清单提供照片.我将相应的代码添加到列表show.html.erb,listing.rb模型,listings_controller.rb和_form.html.erb部分.
当我尝试上传列表的图像时,我收到此错误:
Paperclip::Error in ListingsController#update
Listing model missing required attr_accessor for 'avatar_file_name'
Run Code Online (Sandbox Code Playgroud)
listing_controller的第44行:
def update
respond_to do |format|
if @listing.update(listing_params)
format.html { redirect_to @listing, notice: 'Listing was successfully updated.' }
format.json { head :no_content }
else
Run Code Online (Sandbox Code Playgroud)
要尝试的一些事情:即向listing.rb模型添加一些代码,以使:avatar的可接受图像更加健壮.以下是几个stackoverflow帖子中提到的添加到listing.rb模型的内容:
validates_attachment_content_type :avatar, :content_type => %w(image/jpeg image/jpg image/png)
Run Code Online (Sandbox Code Playgroud)
不幸的是,当我附加图像时,我仍然会遇到相同的错误.当我没有附加图像时,我的默认图像被正确加载并正确创建列表.
我的清单模型:
class Listing < ActiveRecord::Base
has_attached_file :avatar, :styles => { :medium => "150x", :thumb => "100x100>" }, :default_url => "default.jpg"
validates_attachment_content_type :avatar, :content_type => %w(image/jpeg image/jpg image/png)
end
Run Code Online (Sandbox Code Playgroud)
我的_form.html.erb部分:
<%= form_for @listing, :html => { …Run Code Online (Sandbox Code Playgroud) 在过去的几周里,你可能已经看到了我绝望的挫败感.我一直在抓一些等待时间数据,但我仍然无法从这两个站点获取数据
起初我尝试使用BS4 for Python.HCA Virgina的示例代码如下
from BeautifulSoup import BeautifulSoup
import requests
url = 'http://hcavirginia.com/home/'
r = requests.get(url)
soup = BeautifulSoup(r.text)
wait_times = [span.text for span in soup.findAll('span', attrs={'class': 'ehc-er-digits'})]
fd = open('HCA_Virginia.csv', 'a')
for w in wait_times:
fd.write(w + '\n')
fd.close()
Run Code Online (Sandbox Code Playgroud)
所有这些都是打印空白到控制台或CSV.所以我尝试使用PhantomJS,因为有人告诉我它可能正在加载JS.然而,同样的结果!打印空白到控制台或CSV.示例代码如下.
var page = require('webpage').create(),
url = 'http://hcavirginia.com/home/';
page.open(url, function(status) {
if (status !== "success") {
console.log("Can't access network");
} else {
var result = page.evaluate(function() {
var list = document.querySelectorAll('span.ehc-er-digits'), time = [], i;
for (i …Run Code Online (Sandbox Code Playgroud)