ruby-on-rails-3.2

No 'Access-Control-Allow-Origin' header is present on the requested resource

℡╲_俬逩灬. 提交于 2019-11-29 00:59:11
问题 I am using omniauth-facebook with AngularJS and CORS is not working correctly . My omniauth.rb is Rails.application.config.middleware.use OmniAuth::Builder do provider :facebook,"xxxxx", "xxxxx", :scope => 'email,user_birthday,read_stream', :display => 'popup' end Everything works if i use it as rails app and request. But when i try to call 'http:\localhost:3000\users\auth\facebook" via Angular JS $http.get('/users/auth/facebook').success(function(data, status, headers, config) { console.log(

rake assets:precompile attempting to connect to database

試著忘記壹切 提交于 2019-11-29 00:25:13
问题 I'm attempting to debug why my application is attempting to connect to my database when I run rake assets:precompile --trace . I'm probably missing something in the stack trace...anyone see the pertinent line? DEPRECATION WARNING: The InstanceMethods module inside ActiveSupport::Concern will be no longer included automatically. Please define instance methods directly in ActionController::Base instead. (called from <top (required)> at /Users/Kyle/Desktop/skateparks-web/config/application.rb:4)

rails generate model

时光怂恿深爱的人放手 提交于 2019-11-28 21:55:55
问题 I'm trying to follow instructions from the book "Head First Rails" and on page 50 it says to create a model but I am unable to create a model using the rails command. When I type this at this prompt: localhost:~ home$ rails generate model ad name:string description:text price:decimal seller_id:integer email:string img_url:string I get this: Usage: rails new APP_PATH [options] Options: -r, [--ruby=PATH] # Path to the Ruby binary of your choice # Default: /Users/home/.rvm/rubies/ruby-1.9.3-p125

POSTing raw JSON data with Rails 3.2.11 and RSpec

可紊 提交于 2019-11-28 21:02:35
In order to ensure that my application is not vulnerable to this exploit , I am trying to create a controller test in RSpec to cover it. In order to do so, I need to be able to post raw JSON, but I haven't seemed to find a way to do that. In doing some research, I've determined that there at least used to be a way to do so using the RAW_POST_DATA header, but this doesn't seem to work anymore: it "should not be exploitable by using an integer token value" do request.env["CONTENT_TYPE"] = "application/json" request.env["RAW_POST_DATA"] = { token: 0 }.to_json post :reset_password end When I look

Rails console 'y' helper returns NameError rather than yaml-formatting output

梦想的初衷 提交于 2019-11-28 20:42:19
I'm trying to use y object in Rails 3.2.6/Ruby 1.9.3 console to get nicely formatted yaml output for an ActiveRecord object, but for some reason it isn't working for me. I've used it in the past, but somewhere along the way it broke. I get the following output when I try: NameError: undefined local variable or method `yaml' for main:Object The y method is actually an extension to the Kernel object put in place by the Syck YAML parser/emitter . Here are the last few lines of lib/ruby/1.9.1/syck.rb : module Kernel def y( object, *objects ) objects.unshift object puts( if objects.length == 1 YAML

Editing Users With Devise and Omniauth

这一生的挚爱 提交于 2019-11-28 18:26:17
I'm working through the Railscast on implementing Devise and OmniAuth (along with the Devise documentation ) -- currently, I've got a site going where visitors can sign up using their facebook accounts or by filling out a form. I'm running into trouble when users that sign up via OmniAuth try to edit their profiles, though. Devise looks for the user's current password when they submit changes to their profiles, but those that logged in with facebook don't know their passwords (they're set automatically in the user model): def self.find_for_facebook_oauth(auth, signed_in_resource=nil) user =

rake assets:precompile RAILS_ENV=production not working as required

為{幸葍}努か 提交于 2019-11-28 18:13:35
I am trying to precompile assets using the command rake assets:precompile RAILS_ENV=production , but I always get the error below. ** Invoke assets:precompile (first_time) ** Execute assets:precompile /usr/bin/ruby /usr/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets --trace ** Invoke assets:precompile:all (first_time) ** Execute assets:precompile:all ** Invoke assets:precompile:primary (first_time) ** Invoke assets:environment (first_time) ** Execute assets:environment ** Invoke environment (first_time) ** Execute environment ** Invoke tmp:cache:clear (first_time) **

Rails Controller Namespace

坚强是说给别人听的谎言 提交于 2019-11-28 17:18:39
What are advantages and disadvantages of using namespace in ruby on rails. For example: I've many controllers like CompanyLocations CompanyXXXX CompanySports CompanyActivites CompanyQQQQQ I want to put all these controllers in Company folder. What is the rails best practice for this ? Jenorish You have to create a subfolder inside your controller/ directory, and the same in your views/ directory. Your controller file should look like module Company class SportsController < ApplicationController def index end end end ...or class Company::SportsController < ApplicationController def index end

Model.reset_column_information does not reload columns in rails migration

∥☆過路亽.° 提交于 2019-11-28 17:11:18
I'm using Rails 3.2 and have a migration that contains the code: add_column :users, :gift_aid, :integer, :default => 2 # reset columns User.reset_column_information ... code here to load legacy data from sqlite3 database ... # now create a user with the loaded column data user = User.create( ...other cols..., :gift_aid => migrated_gift_aid_column_data, ...other cols... ) and I get unknown attribute: gift_aid when running the migration. User.column_names shows the same list before and after the call to reset_column_information . Oddly when I manually drop the column in mysql and re-run the

Adding a custom seed file

被刻印的时光 ゝ 提交于 2019-11-28 15:38:08
I want to populate a new feature with dummy data, but don't want to use the db/seeds.rb file as it already has seeds other data irrelevant for this feature. To run the default seeds.rb file, you run the command rake db:seed . If I create a file in the db directory called seeds_feature_x.rb , what would the rake command look like to run (only) that file? zeantsoi Start by creating a separate directory to hold your custom seeds – this example uses db/seeds . Then, create a custom task by adding a rakefile to your lib/tasks directory: # lib/tasks/custom_seed.rake namespace :db do namespace :seed