ruby-on-rails-3

Heroku - ActionView::Template::Error (PG::Error: ERROR: column category_products.desc does not exist

梦想与她 提交于 2020-01-16 10:32:30
问题 I am using RailsAdmin and this is the error I get when I click on my model CategoryProduct within RailsAdmin. This is what the error looks like: Started GET "/admin/category_product" for 67.230.41.62 at 2012-12-21 23:20:07 +0000 2012-12-21T23:20:07+00:00 app[web.1]: 2012-12-21T23:20:07+00:00 app[web.1]: ActionView::Template::Error (PG::Error: ERROR: column category_products.desc does not exist 2012-12-21T23:20:07+00:00 app[web.1]: LINE 1: ...ry_products".* FROM "category_products" ORDER BY

initialized friend model in rails

。_饼干妹妹 提交于 2020-01-16 09:09:30
问题 I building an app where a user sign in throw there facebook account and the I grab their friends and their education history. It goes something like this: The user signs in and goes to the SessionsController#Create: class SessionsController < ApplicationController def create user = User.from_omniauth(env['omniauth.auth']) end end The SessionsController method create calls the method .from_omniauth in the User model: def self.from_omniauth(auth) where(auth.slice(:provider, :uid)).first_or

Order by count of has_many :through items in Rails 3

时光怂恿深爱的人放手 提交于 2020-01-16 04:42:09
问题 If I have 3 models: Model Section Model User has_many :votes Model Vote belongs_to :user and inside Model Section has_many :users has_many :votes, :through => :users How to get the Sections list ordered by votes quantity using the AR associations? 回答1: The most reasonable way to do this is to use a subquery written as raw SQL for ordering the result as follows... Section.order( '(select count(1) from votes inner join users on votes.user_id=users.id where users.section_id=sections.id)' ) 回答2:

Trouble on setting the ':controller' parameter for a 'link_to' statement

我是研究僧i 提交于 2020-01-16 04:17:11
问题 I am using Ruby on Rails 3.0.9 and I would like to know why I get the error described below and how can I solve that. In my /views/articles/categories/_content.html.erb file I have: ... <%= link_to("New article", {:controller => content[:article_controller], :action => 'new'}) %> ... If I set the content[:article_controller] to (both setting true and false for the :only_path option) 1. content[:article_controller] = 'articles' 2. content[:article_controller] = '/articles' 3. content[:article

Selecting all columns with Inner Join in Active Record

廉价感情. 提交于 2020-01-16 03:42:07
问题 In the Ruby on Rails Guide I see examples using Joins. For example Category.joins(:posts) results in the query SELECT categories.* FROM categories INNER JOIN posts ON posts.category_id = categories.id This is all well and good, but how can I get returned both the categories AND posts columns using Active Record? Or am I totally missing something with SQL? 回答1: You need to call #includes : Category.includes(:posts) 来源: https://stackoverflow.com/questions/14947820/selecting-all-columns-with

Selecting all columns with Inner Join in Active Record

天大地大妈咪最大 提交于 2020-01-16 03:42:04
问题 In the Ruby on Rails Guide I see examples using Joins. For example Category.joins(:posts) results in the query SELECT categories.* FROM categories INNER JOIN posts ON posts.category_id = categories.id This is all well and good, but how can I get returned both the categories AND posts columns using Active Record? Or am I totally missing something with SQL? 回答1: You need to call #includes : Category.includes(:posts) 来源: https://stackoverflow.com/questions/14947820/selecting-all-columns-with

Error adding value names to devise

試著忘記壹切 提交于 2020-01-16 03:29:18
问题 Im getting an error trying to add the value name to devise, I think all did all things to make it work, but it doesnt work. NoMethodError in Devise/registrations#new undefined method `name' for #<User:0x00000002e4e038> Here is my user model: class User < ActiveRecord::Base include Gravtastic gravtastic :size => 165, :filetype => :png, :rating => 'R' # Include default devise modules. Others available are: # :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and

Failed to build gem native extension ruby racer gem of different version

感情迁移 提交于 2020-01-16 01:31:29
问题 I copied the application from production and did bundle install to install all the missing gems that are in production version and not on my local machine. Gem.lock file has the rubyracer version '0.10.1'. So when it tried to install this version using bundle install following error appeared. Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension. /home/user/.rvm/rubies/ruby-1.9.3-p392/bin/ruby extconf.rb *** extconf.rb failed *** Could not create Makefile due to

Failed to build gem native extension ruby racer gem of different version

空扰寡人 提交于 2020-01-16 01:31:11
问题 I copied the application from production and did bundle install to install all the missing gems that are in production version and not on my local machine. Gem.lock file has the rubyracer version '0.10.1'. So when it tried to install this version using bundle install following error appeared. Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension. /home/user/.rvm/rubies/ruby-1.9.3-p392/bin/ruby extconf.rb *** extconf.rb failed *** Could not create Makefile due to

How to suppress backtrace in Rails?

拈花ヽ惹草 提交于 2020-01-16 01:30:11
问题 When exiting a Rails app using raise or fail , how to prevent the backtrace from being displayed? Tried using back_trace_limit but it only seems to work for the console...? 回答1: You have total control over the backtrace returned with an exception instance by using its set_backtrace method. For example: def strip_backtrace yield rescue => err err.set_backtrace([]) raise err end begin strip_backtrace do puts 'hello' raise 'ERROR!' end rescue => err puts "Error message: #{err.message}" puts