Tag: ruby on rails

引用列名称

我有一个包含2个“不常见”列的表 – order like 。 该表在两个数据库上复制MySQL和PostgreSQL 。 我需要相同的应用程序连接到两个数据库并在两个上使用相同的查询: PageModel.where(“`like` >= ?”, params[:liked]) 这只适用于MySQL 。 如何让ActiveRecord引用列名? 就像是: PageModel.where(“%s >= ?” % quote_column_name(:like), params[:liked]) 我找到了一个现在没用的方法 – 它只返回列名而不引用它。 http://www.rubydoc.info/docs/rails/3.2.8/ActiveRecord/ConnectionAdapters/Quoting:quote_column_name 也许它只是一个占位符,还有另一种方法可以做到这一点?

Twitter bootstrap datetime-picker在模态中没有正确显示

我一直在使用twitter bootstrap datetime-picker和ruby on rails来显示日历,我也在一个模态中使用它,但它显示为部分,因为我试图在屏幕的底部显示 HTML JS $(document).ready(function(){ $(‘#datetimePicker’).datetimepicker(); }); 我也用过这个额外的CSS .bootstrap-datetimepicker-widget { z-index:99999 !important; }

Rails 3.0.7 ActionMailer附件问题

我正在尝试将文件附加到外发电子邮件,但附件大小最终为1个字节。 无论我转发什么附件,它总是以1字节的大小(腐败)结束。 其他一切看起来都不错。 电子邮件信息从IMAP帐户中提取并存储在数据库中以供浏览。 附件存储在文件系统中,其文件名存储为电子邮件的关联记录。 在视图中,可以选择将电子邮件转发给其他收件人。 它适用于Rails 2.3.8,但是对于Rails 3,我必须更改方法的附件部分,所以现在它看起来像…… def forward_email(email_id, from_address, to_address) @email = Email.find(email_id) @recipients = to_address @from = from_address @subject = @email.subject @sent_on = Time.now @body = @email.body + “\n\n” @email.attachments.each do |file| if File.exist?(file.full_path) attachment :filename => file.file_name, :body => File.read(file.full_path) else @body += “ATTACHMENT NOT FOUND: #{file.file_name}\n\n” end end end […]

Rails 3使用嵌套资源进行路由错误

在我的Rails应用程序中,有很多游戏,每个游戏都有自己的排行榜。 因此,将排行榜嵌套在游戏中是有道理的,因此您只能通过游戏进入排行榜。 我设置了我的routes.rb文件(重要部分): resources :games do resources :leaderboards end 所以我更新了我的控制器,以便从传入的game_id获得适当的游戏,并从中获取排行榜信息。 但是,我的问题来自我的观点。 在本节中(从脚手架自动生成的视图): ‘Are you sure?’, :method => :delete %> 代码破解说: No route matches {:action=>”edit”, :controller=>”leaderboards”, :game_id=>#} 这一行,结果是错误:(我的代码中的第19行) 删除此行,视图呈现正常。 因此,URL部分已损坏,但我该如何解决? 奇怪的是,我在Show视图中确实有“edit_game_leaderboard_path”,它运行正常……我做错了什么?

Rails – Dokku – Paperclip:每次推送到生产中断(404s)用户上传的图像

使用Dokku在Digital Ocean上运行Rails 4应用程序。 用户可以通过回形针上传图像。 我可以上传图像,应用程序运行良好并显示所有图像。 一旦我做了一个像文本更改的小改动,我运行$ git push dokku master,所有上传的图像404。 模型: class ProductImage “:rails_root/public/system/:attachment/:id/:basename_:style.:extension”, :url =>”/system/:attachment/:id/:basename_:style.:extension”, styles: { thumb: [“64×64#”, :jpg], medium: [‘200×200>’, :jpg], large: [‘400×400>’, :jpg] } validates_attachment_content_type :image, content_type: /\Aimage\/.*\Z/ belongs_to :product end 我有rails_12factor gem。 这是配置文件: Rails.application.configure do config.cache_classes = true config.eager_load = true config.consider_all_requests_local = false config.action_controller.perform_caching = true config.serve_static_files = ENV[‘RAILS_SERVE_STATIC_FILES’].present? […]

Respond_to混乱

我有一个编辑/更新表单,我通过form_for设置: 在有效数据的情况下,我希望相应的更新操作保存更改,并将用户重定向到他来自的位置。 在这种情况下不需要JS。 如果数据无效,我希望JS处理这种情况。 我把控制器设置成这样: def update @user = current_user @vocab = @user.vocabs.find(params[:id]) if @vocab.update_attributes(vocab_params) flash[:notice] = “Vocab updated!” respond_to do |format| format.js { redirect_back_or(home_user_path(@user)) } end else flash[:error] = “Vocab invalid!” respond_to do |format| format.html { render ‘edit’ } format.js { render file: “vocabs/update.js” } end end end 我遇到的问题是,在有效数据的情况下,保存的URL(study_setup)正在被处理为JS,这可以防止端被加载。 我在哪里告诉Rails使用JS进行此重定向? Started PATCH “/users/1/vocabs/445” for […]

spec with guard,rails 3.1.1和ruby 1.9.3获取无法加载此类文件错误

我刚刚在macbook air上安装了rvm和所有好东西,我用ruby 1.9.3启动了我的rails 3.1.1应用程序。 在我的gem文件中,我放下了警卫和rspec,现在当我尝试单独运行rspec或使用警卫时,我会向我发出错误并且我不确定为什么, 我运行时得到的输出是这样的, phantom:tasks maxmarze$ guard Please install rb-fsevent gem for Mac OSX FSEvents support Using polling (Please help us to support your system better than that). Please install growl_notify or growl gem for Mac OS X notification support and add it to your Gemfile Guard is now watching at ‘/Users/maxmarze/rails_projects/tasks’ Guard::RSpec […]

authlogic rails app中的无限循环

我有一个使用authlogic和facebook的rails应用程序。 在我第一次登录Facebook后不久,我的所有页面都停止响应并显示日志 Processing UserSessionsController#new (for [IP ADDRESS] at 2010-07-08 00:32:31) [GET] Parameters: {“action”=>”new”, “controller”=>”user_sessions”} SystemStackError (stack level too deep): (eval):5:in `connection_handler’ authlogic (2.1.5) lib/authlogic/session/callbacks.rb:83:in `validate’ authlogic (2.1.5) lib/authlogic/session/validation.rb:64:in `valid?’ authlogic (2.1.5) lib/authlogic/session/cookies.rb:110:in `persist_by_cookie’ authlogic (2.1.5) lib/authlogic/session/callbacks.rb:90:in `persist’ authlogic (2.1.5) lib/authlogic/session/persistence.rb:55:in `persisting?’ authlogic (2.1.5) lib/authlogic/session/persistence.rb:39:in `find’ authlogic (2.1.5) lib/authlogic/acts_as_authentic/session_maintenance.rb:96:in `get_session_information’ authlogic (2.1.5) lib/authlogic/acts_as_authentic/session_maintenance.rb:95:in `each’ authlogic (2.1.5) […]

在所有视图中调试输出

我目前正在开发一个新的Rails 3应用程序。 控制器中定义的所有实例变量将在我的视图中自动调试。 这在开发和生产模式中都会发生。 尽管这很有用,但我真的很想摆脱它,因为它会部分地破坏HTML布局。 例如,我在我的控制器中有索引操作: respond_with(@articles = Article.published.order(“created_at DESC”).page(params[:page]).per(5)) 在视图中,您将自动看到类似于的输出的内容,尽管我从不在视图中调用inspect或debug。 用于演示整个问题的示例图片: http://www.diigo.com/item/image/16wox/padm?size=o 我的Gemfile看起来像这样: https ://gist.github.com/1080104

为什么我会在保存重复的Ruby on Rails模型时遇到500错误(未定义的方法’to_model’

我是铁杆新手,但在某些事情上仍然模糊不清 我发送json post请求到/microposts/10/duplicate.json复制微博。 路线转到微博#duplicate Controller的行动是: def duplicate micropost = current_user.microposts.find(params[:id]) new_micropost = micropost.dup respond_with new_micropost.save end 请求的服务器日志是: Started POST “/microposts/15/duplicate.json” for 180.181.247.76 at 2015-09-06 11:00:38 +0000 Processing by MicropostsController#duplicate as JSON Parameters: {“_json”=>15, “id”=>”15”, “micropost”=>{}} User Load (0.3ms) SELECT “users”.* FROM “users” WHERE “users”.”id” = ? LIMIT 1 [[“id”, 2]] Micropost Load (0.3ms) SELECT “microposts”.* […]