Rails

Rails 3 - action mailer SocketError getaddrinfo No such host is known

匿名 (未验证) 提交于 2019-12-03 01:34:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I've configured the action mailer as per http://edgeguides.rubyonrails.org/action_mailer_basics.html My Outgoing Mail Server: mail.xxxx.com (server requires authentication) port 26 and i've the following configuration in config\environments\development.rb config.action_mailer.raise_delivery_errors = true config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = { :address => "mail.xxxx.com", :port => 26, :domain => 'xxxx.com', :user_name => 'dev@xxxx.com', :password => 'dev123', :authentication => 'login', # :enable

Rails gem Ransack -> search 'or condition' with 'is null' and a specific value (field=x OR field IS NULL)

匿名 (未验证) 提交于 2019-12-03 01:34:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I made a support ticket system for our supporters - programmed with ruby on rails (Ruby 1.9.3 Rails 3.2) There is a ticket model with a belongs_to association to users (supporter). I use Ernie's gem Ransack for searching. When the supporter searches his own tickets (handled by tickets_controller.index) he should also see the unassociated tickets in the search result (views/tickets/index) (in combination with the other serach conditions eg. "date" or something else) (So that he can take an open ticket) expected SQL statement: SELECT * FROM

invalid decimal becomes 0.0 in rails

匿名 (未验证) 提交于 2019-12-03 01:34:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have the following rails model: class Product < ActiveRecord::Base end class CreateProducts < ActiveRecord::Migration def self.up create_table :products do |t| t.decimal :price t.timestamps end end def self.down drop_table :products end end But when I do the following in the rails console: ruby-1.9.2-p180 :001 > product = Product.new => #<Product id: nil, price: nil, created_at: nil, updated_at: nil> ruby-1.9.2-p180 :002 > product.price = 'a' => "a" ruby-1.9.2-p180 :003 > product.save => true ruby-1.9.2-p180 :004 > p product #<Product id:

Rails RestClient POST request failing with “400 Bad Request”

匿名 (未验证) 提交于 2019-12-03 01:34:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Looking at the docs there aren't any good examples of how to make a POST request. I need to make a POST request with a auth_token parameter and get a response back: response = RestClient::Request.execute(method: :post, url: 'http://api.example.com/starthere', payload: '{"auth_token" : "my_token"}', headers: {"Content-Type" => "text/plain"} ) 400 bad request error: RestClient::BadRequest: 400 Bad Request from /Users/me/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rest-client-1.8.0/lib/restclient/abstract_response.rb:74:in `return!' from

rails2.0被废弃的用法

断了今生、忘了曾经 提交于 2019-12-03 01:34:01
在Rails2.0当中有大量的用法已经被废弃掉了,在你的应用程序升级到Rails2.0的过程当中必须注意。下面我先列举一下有哪些用法被废弃,然后有什么替代方案,大家请帮我补充: 一、controller的paginate分页方法被拿掉了 2.0以前controller带有paginate这个public的分页方法,现在已经不能使用了。现在推荐的是另外一个替代插件will_paginate,安装这个插件可以用如下的命令: ./script/plugin install svn://errtheblog.com/svn/plugins/will_paginate 关于will_paginate的用法可以参考这个插件里面自带的文档,用法非常简单,或者也可以看作者的博客: http://errtheblog.com/posts/56-im-paginating-again 目前JavaEye2.0的代码也是使用controller的paginate,但是在我们JavaEye3.0代码里面,已经改成了will_paginate。 二、ActionWebServices这个gem包被拿掉了 Rails社区提倡REST,而不是SOAP,如果以前用了SOAP,那么也可以单独安装ActionWebServices,如果是新项目,还是用REST和ActiveResource吧。 三

rails secret_key_base not being recognized in production

匿名 (未验证) 提交于 2019-12-03 01:33:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: So I am trying to deploy my rails app in production. When I go to the page I get a 500 error. When I go to my error logs I get the following error: Exception RuntimeError in Rack application object (Missing `secret_key_base` for 'production' environment, set this value in `config/secrets.yml`) I am running Rails 4.1 and my config/secrets.yml looks like this: development: secret_key_base: <development key> test: secret_key_base: <test key> # Do not keep production secrets in the repository, # instead read values from the environment.

Ruby on Rails - incompatible marshal file format

匿名 (未验证) 提交于 2019-12-03 01:33:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I recently upgraded a Rails v3.x app to Rails 4.1.1 and everything seemed to transition for the most part, but however when I switch the app from production to development in the apache config file, I get the error message We're sorry but something went wrong I know the development environment is working because I can see the GET request being processed in the development.log file. But shortly after the GET request I get the following in the log ActionView::Template::Error (incompatible marshal file format (can't be read) format version 4.8

Rails, how to sanitize SQL in find_by_sql

匿名 (未验证) 提交于 2019-12-03 01:33:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Is there a way to sanitize sql in rails method find_by_sql ? I've tried this solution: Ruby on Rails: How to sanitize a string for SQL when not using find? But it fails at Model.execute_sql("Update users set active = 0 where id = 2") It throws an error, but sql code is executed and the user with ID 2 now has a disabled account. Simple find_by_sql also does not work: Model.find_by_sql("UPDATE user set active = 0 where id = 1") # => code executed, user with id 1 have now ban Edit: Well my client requested to make that function (select by sql)

undefined method `groups&#039; for Rails:Module

匿名 (未验证) 提交于 2019-12-03 01:33:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: As usual I've been an idiot and broken rails on my mac somehow. I think it all started when it said the version of rake wasn't recent enough so I delved down a huge road of different gems etc. and different versions of rails, I ended up getting rails from github but it replaces it with the most recent version. Now I fear all of my configuration files are incorrect, but when I try to 'rake rails:update' I get the following error with a trace: rake aborted! undefined method `groups' for Rails:Module /Users/jamielawrence/Documents/Websites

Rails hidden field undefined method &#039;merge&#039; error

匿名 (未验证) 提交于 2019-12-03 01:33:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I wanna do something like this in rails Here is what I have so far in rails: But then I get this error: undefined method `merge' for "test":String How can I pass values in my hidden_field in rails? 回答1: You should do: "test" %> hidden_field expects a hash as a second argument 回答2: You are using a hidden_field instead of a hidden_field_tag. Because you are using the non-_tag version, it is assumed that your controller has already set the value for that attribute on the object that backs the form. For example: controller: def new ... @order