ruby-on-rails-3.2

Cannot programmatically combine AND and OR conditions using Arel

白昼怎懂夜的黑 提交于 2020-01-15 10:34:12
问题 Given the SQL conditions cond1, cond2 and cond3 generated using Arel operators (.eq for example), I cannot seem to use Arel to produce the SQL: SELECT * FROM <table> WHERE (cond1 AND cond2) OR cond3 This is because to AND conditions together you use .where(), but you can't then .or() the result of .where(). You can only .or() conditions together inside a .where(). I.e. .where and .or are not on the same "level", I would guess one needs a dedicated .and() method on the same level as .or().

Cannot programmatically combine AND and OR conditions using Arel

a 夏天 提交于 2020-01-15 10:31:13
问题 Given the SQL conditions cond1, cond2 and cond3 generated using Arel operators (.eq for example), I cannot seem to use Arel to produce the SQL: SELECT * FROM <table> WHERE (cond1 AND cond2) OR cond3 This is because to AND conditions together you use .where(), but you can't then .or() the result of .where(). You can only .or() conditions together inside a .where(). I.e. .where and .or are not on the same "level", I would guess one needs a dedicated .and() method on the same level as .or().

undefined method 'change' for :Fixnum when updating Timestamp value

核能气质少年 提交于 2020-01-15 08:58:33
问题 I'm using Google's OAuth2 API in a project, using Omniauth to enable creating the initial accounts with little effort, but in order to use the APIs I need to refresh the access_token since they're only valid for an hour, but I'm having an issue updating the expires_at value when I refresh the token. Here's the code I'm using for requesting the token refresh: require 'oauth2' class Identity < ActiveRecord::Base belongs_to :user def refresh_access_token case self.provider when "google" client =

error with rake versioning when running specs in RubyMine; can I manually edit Gemfile.lock

坚强是说给别人听的谎言 提交于 2020-01-15 04:37:29
问题 I started getting this error and would like a way to fix it: You have already activated rake 10.1.1, but your Gemfile requires rake 10.1.0. Using bundle exec may solve this. I am running this from within RubyMine. I can see in my Gemfile.lock where it specifies 10.1.0. Can I just manually update my Gemfile.lock to 10.1.1? If I do: $gem list .... rake (10.1.1, 10.1.0, 10.0.4, 0.9.2.2) So I'm not sure why it isn't just working with 10.1.0? Here's the full output from RubyMine: /Users/jt/.rvm

What to do if “git push heroku master” failed?

喜欢而已 提交于 2020-01-15 03:51:05
问题 I have a working Rails app on my local Windows XP machine. I want to upload it on Heroku. I follow this tutorial https://devcenter.heroku.com/articles/rails3. When I ran git push heroku master , it failed: -----> Ruby/Rails app detected -----> WARNING: Removing `Gemfile.lock` because it was generated on Windows. Bundler will do a full resolve so native gems are handled properly. This may result in unexpected gem versions being used in your app. -----> Installing dependencies using Bundler

Rails: Why “collection=” doesn't update records with existing id?

大憨熊 提交于 2020-01-15 03:47:07
问题 User can have many posts: class User < ActiveRecord::Base has_many :posts accepts_nested_attributes_for :posts end class Post < ActiveRecord::Base belongs_to :user end Why the following sequence doesn't update the first post? $ rails c > user = User.create(name: 'Misha') => #<User id: 7, name: "Misha", ... > > user.posts << Post.create(description: 'hello') => #<ActiveRecord::Associations::CollectionProxy [#<Post id: 9, description: "hello", user_id: 7, ... >]> > post1 = Post.find(9) > post1

Devise, Omniauth and multiple models with STI

[亡魂溺海] 提交于 2020-01-14 14:41:31
问题 I have an application setup with devise authentication using sti (base user model and two other models - company and individual - inheriting from it). From a devise perspective, everything is working. I can have different routes for signup forms and everything works as expected. Now I wanted to give both users (company and individual) the option to signup/sign in using facebook or linked in. If I set the :omniauthable on both models, and set the devise_for on my routes.rb for each model, I

The “create new entry” page on a many-to-many-relationship

岁酱吖の 提交于 2020-01-14 06:22:13
问题 I am a new rails user. This is probably a very basic question, but I need help I am making an app that has a Bands table, a Festivals table, and a Participations table in a many-to many relationship. My models are as follows: class Band < ActiveRecord::Base attr_accessible :year, :genere, :name, :country has_many :participations has_many :festivals, :though => :participations end class Festival < ActiveRecord::Base attr_accessible :city, :name, :country has_many :participations has_many

Rails send_file don't play mp4

元气小坏坏 提交于 2020-01-13 03:56:10
问题 I have a Rails app that protects the uploaded videos putting them into a private folder. Now I need to play these videos, and when I do something like this in the controller: def show video = Video.find(params[:id]) send_file(video.full_path, type: "video/mp4", disposition: "inline") end And open the browser(Chrome or FF) at /videos/:id it doesn't play the video. If I put the same video at the public folder, and access it like /video.mp4 it will play. If I remove the dispositon: "inline" it

undefined method `explain' for #<ActiveRecord::ConnectionAdapters::MysqlAdapter

瘦欲@ 提交于 2020-01-12 19:14:09
问题 I'm new to Ruby on Rails, but I have followed some tutorials and know my way around a little bit. I have generated some scaffolding and inserted data into a MySql database. When navigating to index.html.erb I receive the error in the title The controller is executing index def index @beers = Beer.all respond_to do |format| format.html # index.html.erb format.json { render :json => @beers } end end And has this as a structure Beer: id, brewer_id, name, price, score, color, brew_type, create_at