ruby-on-rails-3

Filter by count of children using Rails 3

允我心安 提交于 2019-12-23 13:09:36
问题 I'd like to select posts that have one or more comments using Rails 3 and a single query. I'm trying something like this: Post.includes(:comments).where('count(comments.id)>0') However I get this error: ActiveRecord::StatementInvalid: PGError: ERROR: aggregates not allowed in WHERE clause I've googled this and similar approaches, group by, etc with no luck. Any help will be appreciated. 回答1: I'm sure you may have figured this out by now, but I believe what you're looking for is the having(

NoHandlerError with Rails3 and Paperclip

末鹿安然 提交于 2019-12-23 13:08:14
问题 So this is my first question on StackOverflow. I'm trying to implement Paperclip on Rails 3.2.3, and after clicking "submit" to create a profile with an uploaded image, I get: Paperclip::AdapterRegistry::NoHandlerError in UsersController#update No handler found for "Screen Shot 2012-09-01 at 11.03.43 AM.png" My server log reads, Paperclip::AdapterRegistry::NoHandlerError (No handler found for "Screen Shot 2012-09-01 at 11.03.43 AM.png"): app/controllers/users_controller.rb:65:in block in

Capybara & RSpec

こ雲淡風輕ζ 提交于 2019-12-23 13:03:23
问题 I can't make Capybara to work successfully, it complains that has_text is an undefined method. I have created a new rails 3.1 project ( rails new test -T ). Gemfile: source 'http://rubygems.org' gem 'rails', '3.1.3' gem 'sqlite3' group :assets do gem 'sass-rails', '~> 3.1.5' gem 'coffee-rails', '~> 3.1.1' gem 'uglifier', '>= 1.0.3' end gem 'jquery-rails' group :test do gem 'rspec-rails' gem 'capybara' end I have installed the spec folder: rails g rspec:install . spec/spec_helper.rb: ENV[

Rails add two scope with active record result

这一生的挚爱 提交于 2019-12-23 12:58:30
问题 I am using acts-as-taggable-on gem i use single field to search by tag_name and user_name User.rb class User < ActiveRecord::Base acts_as_taggable attr_accessor: :user_name, :age, :country, tag_list scope :tagged_with, lambda { |tag| { :joins => "INNER JOIN taggings ON taggings.taggable_id = user.id\ INNER JOIN tags ON tags.id = taggings.tag_id AND taggings.taggable_type = 'User'", :conditions => ["tags.name = ?", tag], :order => 'id ASC' } } def self.search(search) if search where('name LIKE

Why is Heroku rejecting this git push?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-23 12:43:10
问题 I make a new Heroku app inside of my current app directory using Heroku create and ran this: MyMac:bodb pawel$ git push heroku master Counting objects: 359, done. Delta compression using up to 2 threads. Compressing objects: 100% (291/291), done. Writing objects: 100% (359/359), 13.83 MiB | 2 KiB/s, done. Total 359 (delta 40), reused 0 (delta 0) ! Heroku push rejected due to an unrecognized error. ! We've been notified, see http://support.heroku.com if the problem persists. To git@heroku.com

Rails delete link JavaScript ajax call

安稳与你 提交于 2019-12-23 12:43:01
问题 I want to create an ajax delete call. When the link is clicked, the confirm box should appear and then the p tag fades out (comment). The problem is just how the ajax call should be and how to show the confirm box. HTML view: <a rel="nofollow" data-method="delete" data-confirm="Er du sikker?" class="softdelete" href="/blogs/5/comments/18">slet</a> jQuery: <script type="text/javascript"> $(document).ready(function() { $('.softdelete').click(function () { var Url = $(this).attr('href'); var

nested_form gem add works but remove fails…why?

杀马特。学长 韩版系。学妹 提交于 2019-12-23 12:42:28
问题 I'm using the madebydna version of Ryan Bates' nested_form gem from GitHub (can be found at https://github.com/madebydna/nested_form). I'm using the forked version for jQuery support as opposed to Prototype. UPDATE: Check the bottom of the page for an update to this question. EDIT: I'm using: RoR v3.0.5, jQuery v1.4.3, Ruby v1.9.2 END EDIT EDIT: It appears the current structure of the pictures_attributes parameter passed along to the server is causing an issue, at least from what I've seen on

nested form with polymorphic models

夙愿已清 提交于 2019-12-23 12:39:08
问题 I'm making an app with the following attributes, and I'm working on a creating a single form to be able to save a goal, a goal's tasks, a goal's milestones, and a milestone's tasks. #app/models/goal.rb has_many :tasks, :as => :achievement has_many :milestones accepts_nested_attributes_for :tasks accepts_nested_attributes_for :milestones #app/models/milestone.rb belongs_to :goal has_many :tasks, :as => :achievement #app/models/task.rb belongs_to :achievement, :polymorphic => true Whenever I

Rails PaperClip Attachments, knowing if there's a image thumbnail?

淺唱寂寞╮ 提交于 2019-12-23 12:30:46
问题 I'm using Rails 3 paperclip and allow users to upload attachments to the attachment model. If the file is an image, the app generates image previews. If the file is not, it only uploads the file (no image previews). Now I would like to display a list of all the attachments in the DB. So I use attachment.attachment(:large) and that works fine for image attachments, but errors (obviously) for non-image attachments. What's a good way to check if it's an image attachment or not? If not, I'd like

Rails open-uri breaking on path

放肆的年华 提交于 2019-12-23 12:29:43
问题 I'm trying to get a url using open-uri. my code is outrageously simple url = open("http://localhost:3000/descriptions") return render :text => url.to_json When I run this code, I get a timeout error. When I request just "http://localhost:3000", I get my home page (which is correct). So it seems this is breaking on the path somewhere. I've tried using net-http with uri (not sure if that would make a difference) and I still have the same issue. I want to get a path and a query, but I can't seem