ruby-on-rails-3.1

How can I handle this type of multi level forms in rails

不羁岁月 提交于 2019-12-04 14:16:32
问题 I am in rails 3.1. I have the following models class Tool < ActiveRecord::Base has_many :comments end class Comment < ActiveRecord::Base belongs_to :tool has_many :relationships has_many :advantages, :through => :relationships, :source => :resource, :source_type => 'Advantage' has_many :disadvantages, :through => :relationships, :source => :resource, :source_type => 'Disadvantage' end class Relationship < ActiveRecord::Base belongs_to :comment belongs_to :resource, :polymorphic => true end

Rails 3.1 ckeditor

坚强是说给别人听的谎言 提交于 2019-12-04 14:14:26
问题 So I just tried to install ckeditor in rails, however it doesn't look like its working. Here is what I did added these lines to my gemfile gem "ckeditor", "~> 3.6.0" gem "paperclip" Then bundled installed and ran rails generate ckeditor:install rails generate ckeditor:models --orm=active_record Added this file tom config/application.rb config.autoload_paths += %W(#{config.root}/app/models/ckeditor) And then I tried out this code: <%= javascript_include_tag :ckeditor %> cktext_area_tag("test

Direct Uploads to S3 using Carrierwave

眉间皱痕 提交于 2019-12-04 13:05:06
问题 I've recently converted the below from using Paperclip to Carrierwave uploading to Amazon S3 so I can make use of the carrierwave_direct gem and then Sidekiq or another background processing gem. class Release < ActiveRecord::Base has_many :releases_tracks, :dependent => :destroy has_many :tracks, :through => :releases_tracks, :order => "releases_tracks.position DESC" accepts_nested_attributes_for :tracks, :reject_if => lambda { |a| a[:name].blank? }, :allow_destroy => :true accepts_nested

Rake error :warning: already initialized constant MAJOR [duplicate]

久未见 提交于 2019-12-04 11:38:21
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: Problem to run comand rake yulong@ubuntu:~/depotnew$ rake db:migrate /home/yulong/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/version.rb:4: warning: already initialized constant MAJOR /home/yulong/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/version.rb:5: warning: already initialized constant MINOR /home/yulong/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/version.rb:6: warning: already

Using the Bubble sort method for an array in Ruby [closed]

不羁岁月 提交于 2019-12-04 11:32:14
Closed . This question needs to be more focused. It is not currently accepting answers. Learn more . Want to improve this question? Update the question so it focuses on one problem only by editing this post . Closed 2 years ago . I'm trying to implement the Bubble sort method into an easy coding problem for Ruby, but I'm having some trouble. I understand the idea is to look at the value of the first element and compare it to the value of the second element and then swap them accordingly, but I can't seem to do it in an actual problem. Would anyone be willing to provide a brief example of how

Elastic Search/Tire: How to map to association attribute?

别说谁变了你拦得住时间么 提交于 2019-12-04 11:25:37
I'm using Tire for Elastic Search. In my application I have 2 models; Price and Product. I'm trying to search my Price class and use the Product it belongs to's :name attribute for the search field. Right now if I had a product called Product 1 and type in "pro", "prod" or "duct", no results come up. But typing "product" or "Product" shows the results. I believe the problem lies in my mapping. I looked at the query and its: ...localhost:3000/search/results?utf8=%E2%9C%93&query=product When I think it should be: ...localhost:3000/search/results?utf8=%E2%9C%93&query:product=product Judging by

Rails 3.1 Having iframe in view makes layout stop rendering

微笑、不失礼 提交于 2019-12-04 11:09:46
So I have a basic layout file: <!DOCTYPE html> <html dir="ltr" lang="en-US"> <head> <%= stylesheet_link_tag "logged_out" %> <%= javascript_include_tag "application" %> <%= stylesheet_link_tag "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/ui-lightness/jquery-ui.css" %> </head> <body> <!-- header stuff here --> <%= yield %> <!-- footer stuff here --> </body> </html> And with any normal html its fine. However if I add in an iframe like this to a view: <iframe id="form" height="480" width="320" src="/mobile_preview/preview"/> When I render the page everything is rendered up until

How to rescue exception central and DRY?

早过忘川 提交于 2019-12-04 10:50:22
I have an exception that is produced at ~20 seperate places. It can be rescued easy and in the same way at every place but thats not dry and eaven a crapy work! I want to rescue this exception at a central position. How can I arrange this? Its about the ActiveRecord::RecordNonUnique exception by the way,... What about this ? def rescue_from_record_non_unique yield rescue ActiveRecord::RecordNonUnique # your code end # ... rescue_from_record_non_unique do # do something end 来源: https://stackoverflow.com/questions/8644577/how-to-rescue-exception-central-and-dry

Ruby - Multiplication issue

人盡茶涼 提交于 2019-12-04 09:55:30
My output is like this - ruby-1.9.2-p290 :011 > 2.32 * 3 => 6.959999999999999 And I remember sometime back on another machine I had got it like.. 2.32 * 3 = 6 What is my mistake? Thanks a ton for reading this. :) If you really want to round down to an integer then just (3 * 2.32).to_i but I think that's unlikely. Usually you just want to format the slightly imprecise floating point number to something like this "%0.2f" % (3 * 2.32) => "6.96" If you really want to work with the exact representation then you can use BigDecimal . require 'BigDecimal' (3 * BigDecimal.new("2.32")).to_s("F") => "6

missing fingerprints in asset paths

泪湿孤枕 提交于 2019-12-04 09:39:00
We just deployed a Rails 3.1 app using the new asset pipeline. In Development everything looks fine, but in production all asset-images are missing. When deploying we followed the Ruby on Rails Edge Guide. As an example, a simple code snippet from our app: asset_path "favicon.png", "images" This generates in production: /assets/favicon.png But the fingerprint is missing (and therefore it is a deadlink on production). We already tried it without the "images", with image_tag instead. Nothing is working. Additional Information: Rails Version 3.1.0 Already looked at and tried: https://github.com