ruby-on-rails-3

Understanding Rails ActiveRecord “single model” self joins

只愿长相守 提交于 2021-02-05 13:25:20
问题 I'm having a hard time understanding how to implement a single model self-join in Rails. The Guide to ActiveRecord Associations section 2.10 briefly explains Self-Joins but doesn't offer enough information, and every example or post about this such references the Friendly Friend Railcast example that isn't a single model self join, as described in the Rails Guide section 2.10. The idea is a model that has_many and belongs_to itself, without needing a separate table for the relationship. The

SQL statement working in MySQL not working in Postgresql - Sum & group_by rails 3

淺唱寂寞╮ 提交于 2021-01-29 13:29:06
问题 So I'm very new to working in SQL in general, let alone rails but I have this statement that works in MySQL: portfolio_values.select("portfolio_values.*, SUM(portfolio_values.value) as totals").group("portfolio_values.day").map(&:totals) But in postgresql is throws this error: GError: ERROR: column "portfolio_values.id" must appear in the GROUP BY clause or be used in an aggregate function : SELECT portfolio_values.*, SUM(portfolio_values.value) as totals FROM "portfolio_values" WHERE

Rails how to save the requested url?

半城伤御伤魂 提交于 2021-01-29 08:35:25
问题 I have two different ways to access the url "localhost:3000/childrens/new". I have a drop down in childrens/new page and when the user selects an option through the drop down, it shows the different partials using ajax to call the childrens#new method. accessing the childrens new page from url "localhost:3000/parents" accessing the childrens new page from url "localhost:3000/parents1" After the children have been successfully created, the user should be redirected to the relevant url (either

sign_in_and_redirect with omniauth-facebook to specific language

倾然丶 夕夏残阳落幕 提交于 2021-01-29 05:43:01
问题 I'm using omniauth-facebook gem with rails 3.2 and devise 2.0. I have a website with 2 languages, english and spanish. http://localhost:3000/en http://localhost:3000/es The gem works fine for english users because in omniauth_callbacks_controller.rb the redirect go to http://localhost:3000/en This is my omniauth_callbacks_controller.rb for facebook: def facebook @user = User.find_for_facebook_oauth(request.env["omniauth.auth"], current_user) if @user.persisted? flash[:notice] = I18n.t "devise

Rspec: Test rescue block

ε祈祈猫儿з 提交于 2021-01-28 18:24:05
问题 I have a block like this: begin response = Facebook.make_profile_request(params[:token]) rescue => e Airbrake.notify( :error_class => "Facebook Processing", :error_message => "Error: #{e.message}" ) flash[:notice] = "Uh oh...something went wrong. Please try again." redirect_to root_path end This is what I have so far: it "should notify Airbrake if call to FB fails" do Facebook.stub(:make_profile_request).with(fb_token).and_raise(Exception) Airbrake.should_receive(:notify) get :facebook

New Image not Rendering in Rails 3.1

青春壹個敷衍的年華 提交于 2021-01-28 09:06:31
问题 I have just added a new loading wheel to my site in assets/images/loading.gif. The gif does work in development, but in production, the browser renders a broken image icon, with no errors. The server is showing the file as 0 bytes, but when I locate the file in the terminal, I can see that it is 3.2k. Other images from assets/images do work. After searching, I tried several things including precompile and changing lines in my config, but as yet, none have worked. Could it be a permissions or

Rails Custom Delayed Job - uninitialized constant

梦想与她 提交于 2021-01-28 03:12:36
问题 I've been successfully using delayed_job for a couple of years now but recently I have a need to implement some kind of success/failure callback/hooks. Following the delayed_job guide on github i've set up the following custom job: class XmlImportJob < Struct.new(:file, :supplier_id, :user_id, :directory) def perform Product.xml_import(file, supplier_id, user, directory) end def success(job) ProductMailer.xml_import_complete.deliver end def failure(job) ProductMailer.xml_import_failed.deliver

Verify emails accounts without getting black listed?

孤街醉人 提交于 2021-01-28 00:14:56
问题 I just used the email_verifier gem (https://github.com/kamilc/email_verifier) to check if a list of emails was valid (ie. email account exists on a given server). Unfortunately this has blacklisted my own IP on several servers since it turns out that this gem pretends to send email. Is there a (different) way to verify that an email account exists without getting blacklisted? 来源: https://stackoverflow.com/questions/17685624/verify-emails-accounts-without-getting-black-listed

Logs (both development and product) and server output not working rails 3

假如想象 提交于 2021-01-27 22:54:20
问题 the development.log in my application has never worked since the beginning of creating the application. I pull other projects from github, run them and the logs work perfectly fine. the SQL queries don't get logged to the server console either. I usually just see something like Started GET "/admins/queued_users/3" for 127.0.0.1 at 2011-07-29 15:16:46 -0700 Processing by Admins::QueuedUsersController#show as HTML Parameters: {"id"=>"3"} Rendered admins/queued_users/show.html.erb within layouts

Disable IP address logging Rails

梦想与她 提交于 2021-01-27 15:51:10
问题 I am trying to disable logging of IP addresses while handling the request. But I am not able find a way to do this. I want to disable logging of IP for limited portion of my app where user is not yet authenticated. So my questions is How to disable logging of IP in rails log for specific pages(so the IP will not be saved in any log) I am using Rails 3.2.17 EDIT: Here is sample log (from environment.log) Started GET "/my_path" for 192.168.0.109 at 2014-03-28 11:53:20 +0530 I do not want to