Tag: ruby on rails 3.1

覆盖设计after_sign_up_path_for不起作用

在路由中,我的根路径指向”home#index” #index “home#index”但是当我尝试覆盖它时,after_sign_up_path_for在我登录或注册时会将我重定向到根路径。 我试图将它放在设计子类控制器和application_controller中,但它没有用。 我需要做什么? 应用控制器 class ApplicationController < ActionController::Base protect_from_forgery def after_sign_up_path_for(resource) show_cities_path(resource) end end 登记控制员 class RegistrationsController < ApplicationController def after_sign_up_path_for(resource) show_cities_path(resource) end end 路线 root :to => “home#index”

警告。 保存缓存时遇到错误…无法转储匿名类

当使用capistrano部署app时,在production.log中会出现错误。 Compiled signup.css (30ms) (pid 31797) Warning. Error encountered while saving cache /home/deployer/apps/example.com/releases/20140315211501/tmp/cache/sass/c76a96d592cb37dc7092a4e2f10ad8d3d22bcc8b/user_sessions.css.scssc: can’t dump anonymous class # Compiled user_sessions/user_sessions.css (16ms) (pid 31797) Compiled user_sessions.css (20ms) (pid 31797) Warning. Error encountered while saving cache /home/deployer/apps/example.com/releases/20140315211501/tmp/cache/sass/a59f84087c66a48b1521281da138ce9e3ed4c217/welcome.css.scssc: can’t dump anonymous class # 这是我正在使用的Gemfile.lock。 GIT remote: git://github.com/tomazzlender/letter_opener.git revision: 29b17fefe87b8fdc7ead987dbfabe355b59ff684 specs: letter_opener (0.0.2) launchy GIT remote: git://github.com/tomazzlender/premailer.git revision: 88af5e6f60ac78ef1d70d6f0a6f4b7612d2c5f7a […]

facebook打开图形爬虫在rails操作中触发json响应

出于某种原因,facebook爬虫正在我的rails操作中触发json响应。 这导致操作只返回对象的json表示,而没有正常的html标记+打开图标记。 我用rails 3.2.6对它进行了测试。 我使用facebook开放图调试器来查看刮板所看到的内容: http : //developers.facebook.com/tools/debug 。 代码非常简单。 想象一下对象的简单“显示”动作,例如用户。 它结束于: respond_to do |format| format.js { render :json => @this.to_json } format.html end facebook抓取工具正在触发format.js,这会导致无法呈现打开的图形标记。 任何想法为什么会发生这种情况或如何解决它? 谢谢。

Cucumber Rails 3.1未初始化的常量ActionController :: Dispatcher(NameError)

我正在使用Rails 3.1应用程序,我正在将黄瓜集成到我的应用程序中,但是当我尝试运行它时,我得到了这个奇怪的错误,有人可以帮助我吗? Using the default profile… uninitialized constant ActionController::Dispatcher (NameError) /Users/chinog9/.rvm/gems/ruby-1.9.2-p180/gems/cucumber-rails-0.3.2/lib/cucumber/rails/action_controller.rb:51:in `rescue in ‘ /Users/chinog9/.rvm/gems/ruby-1.9.2-p180/gems/cucumber-rails-0.3.2/lib/cucumber/rails/action_controller.rb:42:in `’ /Users/chinog9/.rvm/gems/ruby-1.9.2-p180/gems/cucumber-rails-0.3.2/lib/cucumber/rails/world.rb:27:in `’ /Users/chinog9/INNKU/tacos/features/support/env.rb:11:in `’ /Users/chinog9/.rvm/gems/ruby-1.9.2-p180/gems/cucumber-0.10.2/lib/cucumber/rb_support/rb_language.rb:143:in `load’ /Users/chinog9/.rvm/gems/ruby-1.9.2-p180/gems/cucumber-0.10.2/lib/cucumber/rb_support/rb_language.rb:143:in `load_code_file’ /Users/chinog9/.rvm/gems/ruby-1.9.2-p180/gems/cucumber-0.10.2/lib/cucumber/runtime/support_code.rb:176:in `load_file’ /Users/chinog9/.rvm/gems/ruby-1.9.2-p180/gems/cucumber-0.10.2/lib/cucumber/runtime/support_code.rb:78:in `block in load_files!’ /Users/chinog9/.rvm/gems/ruby-1.9.2-p180/gems/cucumber-0.10.2/lib/cucumber/runtime/support_code.rb:77:in `each’ /Users/chinog9/.rvm/gems/ruby-1.9.2-p180/gems/cucumber-0.10.2/lib/cucumber/runtime/support_code.rb:77:in `load_files!’ /Users/chinog9/.rvm/gems/ruby-1.9.2-p180/gems/cucumber-0.10.2/lib/cucumber/runtime.rb:137:in `load_step_definitions’ /Users/chinog9/.rvm/gems/ruby-1.9.2-p180/gems/cucumber-0.10.2/lib/cucumber/runtime.rb:39:in `run!’ /Users/chinog9/.rvm/gems/ruby-1.9.2-p180/gems/cucumber-0.10.2/lib/cucumber/cli/main.rb:43:in `execute!’ /Users/chinog9/.rvm/gems/ruby-1.9.2-p180/gems/cucumber-0.10.2/lib/cucumber/cli/main.rb:20:in `execute’ /Users/chinog9/.rvm/gems/ruby-1.9.2-p180/gems/cucumber-0.10.2/bin/cucumber:14:in `’ /Users/chinog9/.rvm/gems/ruby-1.9.2-p180/bin/cucumber:19:in `load’ /Users/chinog9/.rvm/gems/ruby-1.9.2-p180/bin/cucumber:19:in `’ 这是我的env.rb: ENV[“RAILS_ENV”] ||= “test” require File.expand_path(File.dirname(__FILE__) + […]

何时在rails中创建新控制器

我想知道你何时知道你需要在rails应用程序中创建一个控制器。 例如,我正在阅读使用Rails的Agile Web Development中的教程,该应用程序创建了几个模型,所有模型都具有单独的视图和控制器。 但是,我们还创建了一个Store控制器,但没有与之关联的模型。 为什么我们需要一个没有型号的控制器? 模型的控制器难道无法处理所有必需的操作吗? 这是常见的吗? 如果是这样,你如何确定何时需要控制器? 谢谢! 这些答案有帮助,谢谢。 我担心的是,当我自己开发一些东西时,我会开始创建无用的控制器,或者在另一方面,不会创建必要的控制器。 但是,我想我需要停止将控制器和模型视为1-1关系,对吗? 如果我理解正确,可能有许多控制器访问模型,并且在一个控制器中使用了许多模型?

在Rails应用程序中放置私有文档的位置?

我有一些模板文件,我想在我的rails应用程序中使用。 我想知道给出两个场景的位置(在哪个目录下): 它们是我的应用程序专用的(只有网站站长可以删除,更改它们) 它们是我的应用程序的私有,但也可以由管理员管理(删除,修改)

Rails:使用带有Asset Pipeline的livereload

铁轨的快速问题在那里有所帮助…… 使用Rails 3.0.x应用程序时,我是Guard和LiveReload的重要用户。 但是,似乎在Rails 3.1中使用资产管道时,livereload guard不知道对Sass文件的更改应该触发向浏览器发送新的css。 有人使用LiveReload和Asset Pipeline吗? 如果是这样,你是如何使它工作的? 谢谢!

Rails 3.2 has_many通过表单提交

我有一个has_many:通过表单,我无法获得额外的属性发布到数据库。 我在某个地方搞砸了参数名称。 我可以获取外键发布,但我有另一个属性,我试图在连接表中跟踪。 请记住,这是一个100%基于ajax的forms。 这就是我所知道的 编辑:在研究类似的问题后,我理解我应该构建表单属性,但我发现的代码由于某种原因不起作用。 这是一些资源。 http://railsforum.com/viewtopic.php?id=20203 Rails 3,嵌套的多级表单和has_many通过 我不明白的是,附加product_ids是内置到rails中的。 那些价值观。 为什么将quantity_shipped属性附加到该数组很难? Models and Relationships Shipment has_many :products :through => :product_shipments Product has_many :shipments :through => :product_shipments ProductShipments belongs_to :shipment, belongs_to :product ProductShipments table t.integer :shipment_id t.integer :product_id t.integer :qty_shipped <– This is the Problem Child 此部分循环显示几次显示来自某个供应商的所有产品。 它为product_ids生成一个数组,为product_shipments数量生成另一个数组。 _product_shipments.html.erb。 Assign Products to Ship product.id […]

将CKEditor与Rails 3.1 Asset Pipline集成

我是资产管道的新手,刚刚从Rails 3.0迁移过来。 我正在努力让CKEditor进入管道,但是它的所有gem都不清楚它们是如何工作的,并且很少或没有使用说明。 我更愿意在不使用gem的情况下执行此操作,因为似乎我所要做的就是将源文件放入vendor/assets目录中,然后将它们包含在application.js 。 我已经尝试过,但是,当我预编译并推送到生产时,似乎找不到某些文件(例如, editor.css ),并且编辑器根本没有显示(只是空白区域)。 的application.js //= require jquery //= require jquery_ujs //= require ckeditor/ckeditor //= require_self 这与vendor/assets/javascript/ckeditor/的源文件vendor/assets/javascript/ckeditor/ ,并指向ckeditor.js 。 我只是不确定从哪里开始。 此代码在开发中工作正常,但在生产中不起作用。 我正在运行rake assets:precompile在添加和提交git之前rake assets:precompile ,然后推送到heroku。

如何防止Rails 3.1将静态资产缓存到Rails.cache?

我在我的Rails 3.1应用程序上使用CloudFlare CDN。 Cloudflare是一种在DNS级别工作的CDN。 在第一次打到静态资产时,CloudFlare会从您的应用程序加载它,然后将其缓存在CDN中。 从CDN而不是您的应用程序加载该资产的未来请求。 我遇到的问题是,如果将控制器缓存设置为true: config.action_controller.perform_caching = true 它启用了Rack :: Cache中间件。 由于Rails为静态资产设置了默认缓存控制设置,因此这些资产将写入Rails.cache存储。 结果,我的缓存存储(在我的情况下是redis)被填充了静态资产,其中url作为哈希键。 遗憾的是,我无法关闭静态资产缓存控制标头,而不会影响Cloudflare和我的用户的浏览器如何缓存资产。 我无法关闭控制器缓存或丢失页面/操作/片段缓存。 如果我删除Rack :: Cache中间件,结果相同。 有没有人有任何其他想法? 更新:我在GitHub上打开了一张票。