Tag: ruby on rails 2

为什么Rails在我的表单中没有识别为空?

我正在改造一个Rails 2网站。 现在,我收到一个错误,我认为这是因为一个值被提交为空白而不是.nil。 但是,我试图保持零状态似乎不起作用。 我感谢您提供的任何帮助。 从模型,基于Make blank params [] nil NULL_ATTRS = %w( start_masterlocation_id ) before_save :nil_if_blank protected def nil_if_blank NULL_ATTRS.each { |attr| self[attr] = nil if self[attr].blank? } end 视图 我有jQuery在start_masterlocation_id存在时为这个隐藏字段添加一个值。 我还有jQuery在不存在时删除了field属性。 “start-masterlocation-id-field” %> 最后,这是控制器抛出错误的部分。 这是保存表单(Maptry)的页面的控制器,而不是Newsavedmap的控制器。 我想我必须删除@ newsavedmap.id,@ newsavedmap.mapname和@newavedavedmap.optimize行,因为我要使用表单处理程序,但我不认为这与此错误有关。 调节器 def maptry @itinerary = Itinerary.find(params[:id]) if @itinerary.user_id == current_user.id respond_to do |format| @masterlocation = […]

每当有人试图批量分配受保护的属性时,都会抛出exception

我正在修复客户端应用程序中的一些批量分配漏洞,我想确保Rails没有默默地丢弃大规模分配受保护属性的尝试。 相反,我想抛出一个exception,所以我可以调查。 即,只要这通常出现在日志中: WARNING: Can’t mass-assign these protected attributes: … 我想抛出exception(或者另外) 编辑:我正在使用Rails 2.3.4

ActiveRecord :: StatementInvalid:ArgumentError:负字符串大小(或大小太大):SELECT * FROM

我在尝试在内存中实例化太多对象时遇到此错误。 这是一个Rails 2.3.x应用程序,以SQL Server作为数据库。 >> Shop.count => 14111 >> Shop.all ActiveRecord::StatementInvalid: ArgumentError: negative string size (or size too big): SELECT * FROM [shop] from /Users/lunks/.rvm/gems/ree-1.8.7-2011.03@ums/gems/activerecord-2.3.14/ lib/active_record/connection_adapters/abstract_adapter.rb:227:in `log’ from /Users/lunks/.rvm/ gems/ree-1.8.7-2011.03@ums/gems/activerecord-sqlserver-adapter-2.3.24/lib/active_record/connection_adapters/sqlserver_adapter.rb:1004:in `raw_select’ from /Users/lunks/.rvm/gems/ree-1.8.7-2011.03@ ums/gems/activerecord-sqlserver-adapter-2.3.24/lib/active_record/connection_adapters/sqlserver_adapter.rb:965:in `select’ from /Users/lunks/.rvm/gems/ree-1. 8.7-2011.03@ums/gems/activerecord-2.3.14/lib/active_record/connection_adapters/abstract/database_statements.rb:7:in `select_all_without_query_cache’ from /Users/lunks/.rvm /gems/ree-1.8.7-2011.03@ums/gems/activerecord-2.3.14/lib/active_record/connection_adapters/abstract/query_cache.rb:62:in `select_all’ from /Users/lu nks/.rvm/gems/ree-1.8.7-2011.03@ums/gems/activerecord-2.3.14/lib/active_record/base.rb:665:in `find_by_sql’ from /Users/lunks/.rvm/gems/ree-1.8.7-2011.03@ums/gem s/activerecord-2.3.14/lib/active_record/base.rb:1582:in `find_every’ f rom /Users/lunks/.rvm/gems/ree-1.8.7-2011.03@ums/gems/activerecord-2.3.14/lib/active_record/base.rb:619:in `find’ […]

Rails拆分代码不起作用

我正在使用rails 2.3。 在我的应用程序中使用 val = Party.find(:all, :conditions => [” type in (‘Physician’) || id in (?)”,PartyLabel.find(:all,:conditions=>”label_id=#{Label.find_by_label(“Can Schedule”).id}”).collect{|p| p.party_id if Party.find(p.party_id).respond_to?(“provider_organizations”)}], :with_disabled => true).select{|physician| not physician.provider_organizations.blank? }.collect{|enum| [enum.display_name_schedule, enum.id]} 代码实现一些要求。 现在我想将代码分成两部分。 1. phys = Physician.find(:all, :include => :provider_organizations, :with_disabled => true).select{|physician| not physician.provider_organizations.blank? }.collect{|enum| [enum.display_name_schedule, enum.id]} 它的工作正常..第二部分将是 2. sch = Party.find(:all, :include => [:as_labels], :conditions => […]

问题在Highchart脚本中有空白图形

我按照http://www.highcharts.com/demo/column-basic/skies中的步骤操作,问题是我的控制器到我的Highchart图形的值显示为空白(未显示我的值) 在我的桌子http://sqlfiddle.com/#!2/b7347/5 ,我在我的控制器中使用 |policies| ID POLICY_NUM DATE_INI CATEGORY_ID 1 1234 2013-01-10 1 2 5678 2013-01-10 2 3 3444 2013-02-10 1 4 4577 2013-02-10 2 |categories| ID NAME 1 Life 2 Vehicles 这是我的控制器 def report @jan_life =Policy.find_by_sql(“select count(*) as total from policies Inner join categories ON categories.id =category_id WHere category_id = 1 AND date_ini BETWEEN ‘2013-01-01’ […]

Rails 2.3.4错误,:rails s &&:bundle不工作?

我有一个朋友,他有一个现有的Rails应用程序,根据environment.rb文件,它似乎是在’2.3.4’中构建的。 他有一些问题,并让我为他调查。 我习惯使用Rails 3.2+。 我下载了他的文件并运行了bundle命令并得到了这个响应: Could not locate Gemfile 然后,我尝试通过运行rails s命令在本地检出站点。 我回来了: Usage: rails new APP_PATH [options] Options: -r, [–ruby=PATH] # Path to the Ruby binary of your choice # Default: /Users/stevenbrooks1111/.rvm/rubies/ruby-1.9.3-p429/bin/ruby -m, [–template=TEMPLATE] # Path to some application template (can be a filesystem path or URL) [–skip-gemfile] # Don’t create a Gemfile -B, [–skip-bundle] […]

未定义的方法`end_with?’ for“rake aborted!”:String(NoMethodError)

每当我键入rake db:migrate或rake -T时,我一直面临运行rake任务/命令的问题,它显示错误说未定义的方法`end_with?’ for“rake aborted!”:String(NoMethodError)。使用ruby186,rails238和gem version 1.3.3 rake db:migrate /home/projects/.rvm/gems/ruby-1.8.6-p420@global/gems/rubygems-bundler-1.1.0/lib/rubygems-bundler/regenerate_binstubs_command.rb:48: warning: parenthesize argument(s) for future version /home/a3logics/.rvm/gems/ruby-1.8.6-p420@global/gems/rake-10.0.3/lib/rake/trace_output.rb:14:in `trace_on’: undefined method `end_with?’ for “rake aborted!”:String (NoMethodError) from /home/a3logics/.rvm/gems/ruby-1.8.6-p420@global/gems/rake-10.0.3/lib/rake/trace_output.rb:14:in `map’ from /home/a3logics/.rvm/gems/ruby-1.8.6-p420@global/gems/rake-10.0.3/lib/rake/trace_output.rb:14:in `trace_on’ from /home/a3logics/.rvm/gems/ruby-1.8.6-p420@global/gems/rake-10.0.3/lib/rake/application.rb:322:in `trace’ from /home/a3logics/.rvm/gems/ruby-1.8.6-p420@global/gems/rake-10.0.3/lib/rake/application.rb:176:in `display_error_message’ from /home/a3logics/.rvm/gems/ruby-1.8.6-p420@global/gems/rake-10.0.3/lib/rake/application.rb:169:in `standard_exception_handling’ from /home/a3logics/.rvm/gems/ruby-1.8.6-p420@global/gems/rake-10.0.3/lib/rake/application.rb:70:in `run’ from /home/a3logics/.rvm/gems/ruby-1.8.6-p420@global/gems/rake-10.0.3/bin/rake:33 from /home/a3logics/.rvm/gems/ruby-1.8.6-p420@global/bin/rake:19:in `load’ from /home/a3logics/.rvm/gems/ruby-1.8.6-p420@global/bin/rake:19 from /home/a3logics/.rvm/gems/ruby-1.8.6-p420/bin/ruby_noexec_wrapper:14 我被困在这里的任何帮助。

为什么我的rake调用导致’未定义的方法`source_index`’错误?

我试图运行bundle exec rake db:migrate然后遇到以下错误。 bundle exec rake db:migrate –trace ** Invoke db:migrate (first_time) ** Invoke environment (first_time) ** Execute environment rake aborted! undefined method `source_index’ for Gem:Module C:/Ruby193/lib/ruby/gems/1.9.1/gems/rails-2.3.17/lib/rails/gem_dependency.rb:21:in `add_frozen_gem_path’ C:/Ruby193/lib/ruby/gems/1.9.1/gems/rails-2.3.17/lib/initializer.rb:298:in `add_gem_load_paths’ C:/Ruby193/lib/ruby/gems/1.9.1/gems/rails-2.3.17/lib/initializer.rb:132:in `process’ C:/Ruby193/lib/ruby/gems/1.9.1/gems/rails-2.3.17/lib/initializer.rb:113:in `run’ C:/Program Files/chiliproject-3.7.0/config/environment.rb:42:in `’ C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-2.3.17/lib/active_support/dependencies.rb:182:in `require’ C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-2.3.17/lib/active_support/dependencies.rb:182:in `block in require’ C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-2.3.17/lib/active_support/dependencies.rb:547:in `new_constants_in’ C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-2.3.17/lib/active_support/dependencies.rb:182:in `require’ C:/Ruby193/lib/ruby/gems/1.9.1/gems/rails-2.3.17/lib/tasks/misc.rake:4:in `block in ‘ C:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/task.rb:228:in `call’ C:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.3/lib/rake/task.rb:228:in […]

如何让Rails路由到控制器而不是公共文件夹中的静态文件?

在Rails 2.3应用程序中,我有一个SitemapController其中包含一个sitemap操作,可创建一个人类可读的站点地图页面,以及路径文件中的路径。 在公共文件夹中,有一个搜索引擎的sitemap.xml文件。 问题是http://mysite/sitemap正在提供sitemap.xml ,而不是路由到控制器。 如果我删除sitemap.xml那么它就可以很好地路由到控制器。 在其他几个非常相似的站点上,我们有完全相同的排列,但是那些sitemap.xml的存在并不能阻止Rails路由到控制器。 在这些网站上,正如预期的那样, http://mysite/sitemap路由到SitemapController#sitemap和http://mysite/sitemap.xml提供静态文件。 然而,我一直无法发现可能导致这个问题的任何差异。 任何人都可以建议可能导致这种情况的原因,或者我可能会如何进行调试?

从rails日志中过滤部分或全部请求URL

Rails提供filter_parameter_logging来过滤rails日志中的敏感参数。 如果您有一个JSONP API,URL中可能会出现一些敏感信息。 有没有办法从日志中过滤请求URL?