ruby-on-rails-3

Rails 3 Mechanize - SocketError: getaddrinfo: Host or name not known

微笑、不失礼 提交于 2019-12-24 00:05:06
问题 I am using mechanize and i get this error. Can someone please help me. I have set meta refresh to true. Error log: SocketError: getaddrinfo: Host or name not known form C:/Ruby192/lib/ruby/1.9.1/net/http.rb:644:in 'initiallize' form C:/Ruby192/lib/ruby/1.9.1/net/http.rb:644:in 'open' form C:/Ruby192/lib/ruby/1.9.1/net/http.rb:644:in 'block in connect' form C:/Ruby192/lib/ruby/1.9.1/timeout.rb:44:in 'timeout' form C:/Ruby192/lib/ruby/1.9.1/timeout.rb:87:in 'timeout' form C:/Ruby192/lib/ruby/1

one to one or zero association in rails

女生的网名这么多〃 提交于 2019-12-23 23:35:44
问题 Model I class TimeLog < ActiveRecord::Base has_one :custom_time_fields, :dependent => :destroy end Model II class CustomTimeFields < ActiveRecord::Base belongs_to :time_log end above design in terms of database will be timelogs table + custom_time_field_id(foreign key) custom_time_fields So when i delete timelog entry its associated 'custom_time_field' will be auto deleted by rails But i want database design like following Table I: time_logs Table II custom_time_fields (having time_log_id as

CarrierWave: Single uploader for multiple models?

烈酒焚心 提交于 2019-12-23 23:25:11
问题 How do I make the single image uploader do different actions depending on the model it is creating the image for? I have one image uploader, and I want to upload images for Users and for Posts. For the user, I want the original image & thumbnail (70x70). For the Posts, I want the original image and featured thumbnail (260x180). I could just make 3 versions for every image and just call the desired one, but that's probably really bad since it would clog my storage database. I looked at:

Rails 3 model mapping certain columns to different model attributes

久未见 提交于 2019-12-23 21:38:47
问题 I have the old legacy table called "DXFTACCTS", and I created Rails model "Account". class Account < ActiveRecord::Base set_table_name "DXFTACCTS" end The problem is that DXFTACCTS has fields like "XORFNAME" which I want to be "first_name" in the model, and so on. How do I "map" specific table columns to model attributes? Thanks! 回答1: You can use the method alias_attribute like this: class Account < ActiveRecord::Base set_table_name "DXFTACCTS" alias_attribute :first_name, :XORFNAME end alias

Rails how to optimize my website?

寵の児 提交于 2019-12-23 20:21:07
问题 I want to make my website faster. I know I can make CSS sprites and compress my HTML and CSS. Are there other ways I can optimize my page speed? An example is this page: http://www.vinderhimlen.dk/konkurrencer/vind-elektronik It takes several seconds to load the share buttons, rating stars and Facebook likes. I would really want to optimize it. I just don't think that minimizing the HTML and CSS is enough. 回答1: No matter what you do to scale or increase performance of Rails you will want to

Rails3: Take control over generated JSON (to_json with datamapper ORM)

十年热恋 提交于 2019-12-23 20:19:07
问题 From my Rails 3 app i want a JSON like this: {count:10, pictures:[ {id:1}, ... ] } I tried render( :json => { :count => 10, :pictures => @pictures.to_json(:only=>:id) } ) but in this case, my pictures get escaped ..."pictures":"[{\"id\":2653299}, .... In my old merb app I had the following simple line in my controller: display( { :count=>@count, :pictures => @pictures } ) Because I am using datamapper as my ORM and dm-serializer I am not sure where to influence the generated json. 回答1: Your

actionwebservice and rails 3 /

非 Y 不嫁゛ 提交于 2019-12-23 19:55:37
问题 I'm on a rails 3 project trying to install actionwebservice using: gem 'rails', '3.0.4' gem 'actionwebservice', :git => 'https://github.com/ywen/actionwebservice.git' And I get the error: Bundler could not find compatible versions for gem "activerecord": In Gemfile: actionwebservice depends on activerecord (= 2.3.5) rails (= 3.0.4) depends on activerecord (3.0.4) Any suggestions? 回答1: I had the same problem. Try this gem: https://github.com/dnordberg/actionwebservice gem 'actionwebservice',

File to import not found or unreadable: bootstrap-wysihtml5

本秂侑毒 提交于 2019-12-23 19:36:53
问题 I have a Rails 4rc1 application with multiple engines. I'm using bootstrap-wysihtml5-rails gem in my admin engine. According to documentation I added gem 'bootstrap-wysihtml5-rails' to admin engine's Gemfile. Then when I added @import 'bootstrap-wysihtml5' to admin engine's application.scss . I get below errors: File to import not found or unreadable: bootstrap-wysihtml5. Load paths: /home/zoloo/.rvm/gems/ruby-1.9.3-p429@rails-4rc1/gems/coffee-rails-4.0.0/lib/assets/javascripts /home/zoloo/

Rails: How to connect to an old PostgreSQL (Your version of PostgreSQL (70417) is too old, please upgrade!)

末鹿安然 提交于 2019-12-23 19:26:38
问题 Trying to setup a connection to a remote PostgreSQL, I get the error: RuntimeError: Your version of PostgreSQL (70417) is too old, please upgrade! from /Users/panayi/.rbenv/versions/1.9.3-p362/lib/ruby/gems/1.9.1/gems /activerecord-3.2.11/lib/active_record/connection_adapters /postgresql_adapter.rb:331:in `initialize' I don't have access to the PostgreSQL, so there is no way to upgrade. I've tried to use an older pg gem: # Gemfile gem 'pg', '~> 0.9.0' but then I get: LoadError: Please install

find where column could have multiple values, rails

非 Y 不嫁゛ 提交于 2019-12-23 19:08:27
问题 I'm trying to search where one column could equal one value and the other could have multiple values... This works, with one value for each... <%= Post.where("category LIKE ? OR commentary LIKE?", 20, "%mom%").count %> This does not work... <%= Post.where("category LIKE ? OR commentary LIKE?", 20, [{"%mom%", "%mother%"}]).count %> How would be the best way to solve this in rails? Thank you. 回答1: What you are trying to do is only work with IN You can do as follow; <%= Post.where("category LIKE