小编ped*_*ete的帖子

记录php时出错 - error_reporting(0)没有预期的效果

我有一个非常简单的页面,它获取一个URL并解析一些数据.

我已经在我的页面中内置了一些错误处理,如果响应是404错误.

但是,我似乎无法阻止php吐出以下错误

 Warning: file_get_contents(http://url-to-retrieve.com/123.html) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in /var/www/html/maickl/procs/get.php on line 84

Notice: Undefined offset: 0 in /var/www/html/maickl/procs/get.php on line 91

我用这个页面开始

error_reporting(0)

有关为什么会发生这种情况的任何建议,为什么这些错误没有被抑制(似乎只在这个页面上),以及我能做些什么呢?

php error-handling

3
推荐指数
2
解决办法
9894
查看次数

在Rails中使用MongoMapper的回形针3

我正在尝试在我的第一个rails应用程序中实现Paperclip,我碰巧使用rails 3和mongodb与mongomapper.

我按照本指南将所有事情放在一起工作

正如博客文章所暗示的那样,我将paperclip放入config/initializers目录,我安装了gem,gem在gemfile中(rails 3右边),我运行了捆绑器.

在我的用户类中,我添加了

require 'paperclip'

当我加载应用程序时,我收到以下错误,

undefined method 'has_attached_file' for User:Class

回形针文件如下所示

module Paperclip
  module ClassMethods
    def has_attached_file name, options = {}
      include InstanceMethods

      write_inheritable_attribute(:attachment_definitions, {}) if attachment_definitions.nil?
      attachment_definitions[name] = {:validations => []}.merge(options)

      after_save :save_attached_files
      before_destroy :destroy_attached_files

      define_callbacks :before_post_process, :after_post_process
      define_callbacks :"before_#{name}_post_process", :"after_#{name}_post_process"

      define_method name do |*args|
        a = attachment_for(name)
        (args.length > 0) ? a.to_s(args.first) : a
      end

      define_method "#{name}=" do |file|
        attachment_for(name).assign(file)
      end

      define_method "#{name}?" do
        attachment_for(name).file?
      end

      validates_each name, :logic => lambda {
        attachment …

ruby-on-rails paperclip mongomapper

3
推荐指数
1
解决办法
2772
查看次数

散列中的增量值

我有一堆帖子里面有类别标签.我试图找出每个类别被使用了多少次.

我正在使用带有mongodb的rails,但我不认为我需要从db中获取类别的出现,因此mongo部分应该无关紧要.

这就是我到目前为止所拥有的

@recent_posts = current_user.recent_posts #returns the 10 most recent posts
@categories_hash = {'tech' => 0, 'world' => 0, 'entertainment' => 0, 'sports' => 0}
    @recent_posts do |cat|
       cat.categories.each do |addCat|
         @categories_hash.increment(addCat) #obviously this is where I'm having problems
       end
     end
end

这个职位的结构是

{"_id" : ObjectId("idnumber"), "created_at" : "Tue Aug 03...", "categories" :["world", "sports"], "message" : "the text of the post", "poster_id" : ObjectId("idOfUserPoster"), "voters" : []}

我愿意接受关于如何获得类别数量的建议,但我想最终获得选民的数量,所以在我看来最好的方法是增加categories_hash,然后添加votes.length,但有一件事,我只是想弄清楚如何增加哈希值.

ruby hash

3
推荐指数
1
解决办法
2万
查看次数

Rake db:迁移错误"不知道如何构建任务"

我有一个表,我在需要小数位的字段上使用整数,所以我试图创建一个迁移,将字段类型从整数更改为float/real.我的数据库是sqllite3,我正在使用rails3.

我跑了

rails generate migration ChangeMeasureColumnOnIngredients

创建初始迁移文件,然后将类更新为

class ChangeMeasureColumnOnIngredients < ActiveRecord::Migration
  def self.up
    change_column :ingredients, :measure, :real
  end

我运行了rake db:migrate并且返回正常.

当我通过我的rails应用程序插入一个值时,它没有返回小数位.我开始认为许多rails不知道'real'是什么作为数据类型,因此我将迁移更改为

change_column :ingredients, :measure, :float

然后我跑了

rake db:migrate change_measure_column_on_ingredients
现在我收到以下错误
c:\Ruby192\rails3rc>rake db:migrate change_measure_column_on_ingredients
(in c:/Ruby192/rails3rc)
rake aborted!
Don't know how to build task 'change_measure_column_on_ingredients'
C:/Ruby192/lib/ruby/1.9.1/rake.rb:1720:in []'
C:/Ruby192/lib/ruby/1.9.1/rake.rb:2040:ininvoke_task'
C:/Ruby192/lib/ruby/1.9.1/rake.rb:2019:in block (2 levels) in top_level'
C:/Ruby192/lib/ruby/1.9.1/rake.rb:2019:ineach'
C:/Ruby192/lib/ruby/1.9.1/rake.rb:2019:in block in top_level'
C:/Ruby192/lib/ruby/1.9.1/rake.rb:2058:instandard_exception_handling'
C:/Ruby192/lib/ruby/1.9.1/rake.rb:2013:in top_level'
C:/Ruby192/lib/ruby/1.9.1/rake.rb:1992:inrun'
C:/Ruby192/bin/rake:31:in `'

我尝试将:float更改为:real,但我仍然遇到了这个错误.

谁能告诉我我做错了什么?我是铁杆新手,还在学习.

sqlite rake ruby-on-rails

3
推荐指数
1
解决办法
2万
查看次数

用同位素重新布置物品,似乎没有保持结构

我一直在玩同位素 http://isotope.metafizzy.co/demos/relayout.html 并且一直在尝试创建一个保持固定大小的父容器,总是有6个较小的项目,并重新调整以适应第7个较大的项目.

这是我到目前为止在jsfiddle http://jsfiddle.net/pedalpete/LGBg6/上的内容

我希望会发生的是,在点击任何一个块后,任何一行中较小块的总数将为3.

出于某种原因,无论是用户.isotope('resize'),还是正如我所做的那样求助并重新创建同位素,我最终会在顶行中输入一个大于3的数字,因此这些项目的排序不均匀.

我认为这种安排在诉诸之后会有些不稳定.有没有办法让同位素服从装订盒的宽度和高度参数?

jquery jquery-isotope

3
推荐指数
1
解决办法
1万
查看次数

使用嵌套的json填充嵌套集合

在我的路线解决方案

Myapp.Routes = Backbone.Router.extend({
   init: function(){
        user = new User();
        user.fetch({user,
                     success: function(response){
                             user.classlist = new classes(response.attributes.classes);
           });

   }

});

我从我的服务器返回了一个序列化的json数组,我试图将嵌套对象放入我的嵌套集合中.

这个答案,我认为会让我在那里,但我错过了一些东西. 如何使用Backbone.js从嵌套的JSON构建集合/模型

我试图用我的嵌套模型填充的json是

{first_name: "Pete",age: 27, classes: [{class_name: "math", class_code: 42},{class_name: "french", class_code: 18}]}

我创建了我的用户模型

MyApp.Models.Users = = Backbone.Model.extend({

    initialize: function(){
        this.classlist = new MyApp.Collections.ClassList();

        this.classlist.parent = this;

    }

});

我曾尝试在另一页上关注该示例,并使用

      this.classlist = new MyApp.Collections.ClassList(this.get('classes'));

        this.classlist.parent = this;

this.get('classes')返回undefined.

我也试过通过this.attributes.classes获取classes数组,但这也是未定义的.

------------更新为包括重新初始化--------------------我正在初始化用户和类的函数用户路由并称为重新初始化.我使用此函数来获取用户及其类并存储该对象.

re_initialize: function(id){
            user = new MyApp.Models.User();
            MyApp.editingClasses.url = 'classes/'+id;
            MyApp.editingClasses.fetch({
                        success: function(response){
                        MyApp.editingClasses.parse(response);
                        }
            });

        new …

nested backbone.js

3
推荐指数
1
解决办法
5602
查看次数

Rails无法为id,created_at大量分配受保护的属性

我使用rails作为backbone.js站点的服务器端,因此我不断地来回传递rails对象.

我注意到rails返回的错误WARNING: Can't mass-assign protected attributes: id, created_at, updated_at.

当然,我觉得这很奇怪,因为我从来没有把这些字段包括在内.据我所知,我的json看起来很正常

 Parameters: {"id"=>1, "updated_at"=>"2011-04-21T16:41:02Z"},  "created_at"=>"2012-02-23T21:01:02Z", "action"=>"test update"}

activerecord ruby-on-rails mass-assignment

2
推荐指数
1
解决办法
7239
查看次数

从深度嵌套的activerecord对象返回json

在我的模型中,我有一些相当深的嵌套

-user
   -user_event
        -event
              -location
              -categories
              -attendees

我正在尝试返回一个返回所有嵌套元素的json对象.我可以去

user = User.find(current_user.id).user_event #or ,:includes => :user_event
render :json => user

但我不知道如何一次显示整个哈希值.

activerecord ruby-on-rails-3.1

2
推荐指数
1
解决办法
1487
查看次数

在closes_nested_attributes_for上打破模型,没有关联错误

我有一个Wine模特,一个葡萄酒可以有很多Varietals.

我有一个WineVarietals模型,并通过该表加入葡萄酒到品种.

当我放入accepts_nested_attributes_for :wine_varietals我的模型时,我得到 No association found for namewine_varietals'.它已经定义了吗?`

但我确实在我的模型中有关联.

我的葡萄酒模型是

class Wine < ActiveRecord::Base

    attr_accessible :name, :winery_id, :wine_varietals_attributes
    accepts_nested_attributes_for :wine_varietals

    belongs_to :winery
    has_many :wine_varietals
    #has_and_belongs_to_many :varietals, :join_table => :wine_varietals
    has_many :wine_photos
    has_many :vintages

我也有WineVarietal和Varietal模型.

如果我注释掉该accepts_nested_attributes_for行,则错误就会消失.

我尝试过不同形式的复数wines_varietals,wine_varietal但似乎无法摆脱这种错误.

ruby-on-rails nested-attributes

2
推荐指数
1
解决办法
2019
查看次数

nodemon 不监视 tsx 文件中的更改

我正在尝试测试我的 typescript react 应用程序,并且我让 nodemon 对.ts文件运行 jasmine 测试,但我无法.tsx触发监视操作。

我的 package.json 有一个相当简单的

"test": "cross-env NODE_ENV=test jasmine-ts **/*.spec.ts*",
"test-watch": "nodemon -e ts -w ./ -x npm run test",
Run Code Online (Sandbox Code Playgroud)

我认为*最后spec.ts*会告诉 nodemon 重新运行.ts.tsx但这似乎不起作用。

也没有 .tsx?

nodemon

2
推荐指数
1
解决办法
1153
查看次数