"select * from users, awards where (users.id = awards.user_id) and awards.trophy_id not in (select awards.trophy_id from awards where awards.trophy_id = #{trophy.id})"
This is a really weird problem: I have set up the authlogic_openid_selector_example app. When i register, the email id is not returned by the openid provider the first time. But if i delete the account and register again, the email id is returned. But this doesn't seem to be happening in the example hosted here: http://big-glow-mama.heroku.com/. How do i fix this problem? Has this got to do with caching? I have hosted my version of the app here: http://pingauthtest.heroku.com/
I guess the author of authlogic_openid_selector_example app (@holden) has forgotten to commit new changes. :) I looked at my development log and the first time the provider doesn't return the openid.ext1.value.ext0 which contains the email id. This is returned the second time only after having deleted the account first.
Edit: This is some extra info for debugging:
THIS IS WHEN IT REGISTERS:
OpenIdAuthentication::Association Load (5.3ms) SELECT * FROM "open_id_authentication_associations" WHERE ("open_id_authentication_associations"."server_url" = E'https://www.google.com/accounts/o8/ud')
Generated checkid_setup request to https://www.google.com/accounts/o8/ud with assocication AOQobUde_9BUnQsk91rb_Sf9tguJ-S7Gpkwahc-nvDGDYAC8nphisNqu
Redirected to https://www.google.com/accounts/o8/ud?
openid.assoc_handle=AOQobUde_9BUnQsk91rb_Sf9tguJ-S7Gpkwahc-nvDGDYAC8nphisNqu
&openid.ax.mode=fetch_request
&openid.ax.required=ext0
&openid.ax.type.ext0=http%3A%2F%2Faxschema.org%2Fcontact%2Femail
&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select
&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select
&openid.mode=checkid_setup
&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0
&openid.ns.ax=http%3A%2F%2Fopenid.net%2Fsrv%2Fax%2F1.0
&openid.ns.sreg=http%3A%2F%2Fopenid.net%2Fextensions%2Fsreg%2F1.1
&openid.realm=http%3A%2F%2Flocalhost%3A3000%2F
&openid.return_to=http%3A%2F%2Flocalhost%3A3000%2Faccount%3Ffor_model%3D1%26_method%3Dpost%26open_id_complete%3D1
&openid.sreg.required=email
Completed in 3574ms (DB: 14) | 302 Found [http://localhost/account]
THIS IS WHEN IT USES SESSIONS:
OpenIdAuthentication::Association Load (5.3ms) SELECT * FROM "open_id_authentication_associations" WHERE ("open_id_authentication_associations"."server_url" = E'https://www.google.com/accounts/o8/ud')
Generated checkid_setup request to https://www.google.com/accounts/o8/ud with assocication AOQobUde_9BUnQsk91rb_Sf9tguJ-S7Gpkwahc-nvDGDYAC8nphisNqu
Redirected to https://www.google.com/accounts/o8/ud?
openid.assoc_handle=AOQobUde_9BUnQsk91rb_Sf9tguJ-S7Gpkwahc-nvDGDYAC8nphisNqu
&openid.ax.mode=fetch_request
&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select
&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select
&openid.mode=checkid_setup
&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0
&openid.ns.ax=http%3A%2F%2Fopenid.net%2Fsrv%2Fax%2F1.0
&openid.ns.sreg=http%3A%2F%2Fopenid.net%2Fextensions%2Fsreg%2F1.1
&openid.realm=http%3A%2F%2Flocalhost%3A3000%2F
&openid.return_to=http%3A%2F%2Flocalhost%3A3000%2Fuser_session%3Ffor_session%3D1%26_method%3Dpost%26open_id_complete%3D1
Completed in 2708ms (DB: 15) | 302 Found [http://localhost/user_session]
Googled for this to no avail. Didn't find anything in the API either. I was expecting some kind of class method or configuration option to set it...
So, rather than calling
from "[email protected]"
for every method, it could be called automatically.
I am working on a RoR server setup that uses Thin and Nginx.
It works fine, but only if I manually add the folder /etc/thin and set the permissions to 777 in order to use the command below:
thin config -C /etc/thin/testapp.yml -c /var/www/testapp --servers 1 -e production
If I don't set it to 777, I get this error:
me@UbuntuRails:/etc$ thin config -C /etc/thin/testapp.yml -c /var/www/testapp --servers 1 -e production
/usr/local/rvm/gems/ruby-1.9.3-p286@rails328/gems/thin-1.5.0/lib/thin/controllers/controller.rb:115:in initialize': Permission denied - /etc/thin/testapp.yml (Errno::EACCES)
from /usr/local/rvm/gems/ruby-1.9.3-p286@rails328/gems/thin-1.5.0/lib/thin/controllers/controller.rb:115:inopen'
from /usr/local/rvm/gems/ruby-1.9.3-p286@rails328/gems/thin-1.5.0/lib/thin/controllers/controller.rb:115:in config'
from /usr/local/rvm/gems/ruby-1.9.3-p286@rails328/gems/thin-1.5.0/lib/thin/runner.rb:187:inrun_command'
from /usr/local/rvm/gems/ruby-1.9.3-p286@rails328/gems/thin-1.5.0/lib/thin/runner.rb:152:in run!'
from /usr/local/rvm/gems/ruby-1.9.3-p286@rails328/gems/thin-1.5.0/bin/thin:6:in'
from /usr/local/rvm/gems/ruby-1.9.3-p286@rails328/bin/thin:19:in load'
from /usr/local/rvm/gems/ruby-1.9.3-p286@rails328/bin/thin:19:in'
from /usr/local/rvm/gems/ruby-1.9.3-p286@rails328/bin/ruby_noexec_wrapper:14:in eval'
from /usr/local/rvm/gems/ruby-1.9.3-p286@rails328/bin/ruby_noexec_wrapper:14:in'
I don't like to set this folder to a 777, sounds like a rubbish workaround.
I run everything from an admin user account, not root. RVM runs from my admin user and gem only works in my admin as well. If I sudo that action, nothing happens because my root doesn't "know" thin.
Which is the correct way to handle this?
Thanks!
I'm using will_paginate for pagination, which has been working well so far, except for this one thing.
If I try to paginate a scope, for instance
class User < ActiveRecord::Base
named_scope :scope, lambda { etc }
end
User.scope.paginate({:page => params[:page], :per_page => 10})
That will tell me paginate is an undefined method. I'd rather not have to use a second solution for only this scope, is there something I can do here?
I'm working on a metaprogramming task, where I'm trying to use a single method to define a polymorphic association in the calling class, while also defining the association in the target class. I need to pass in the name of the calling class to get the association right. Here's a snippet that should get the idea across:
class SomeClass < ActiveRecord::Base
has_many :join_models, :dependent=:destroy
end
class JoinModel < ActiveRecord::Base
belongs_to :some_class
belongs_to :entity, :polymorphic=true
end
module Foo
module ClassMethods
def acts_as_entity
has_many :join_models, :as=:entity, :dependent=:destroy
has_many :some_classes, :through=:join_models
klass = self.name.tableize
SomeClass.class_eval "has_many :#{klass}, :through=:join_models"
end
end
end
I'd like to eliminate the klass= line, but don't know how else to pass a reference to self from the calling class into class_eval.
any suggestions?
I have auto registration working with authlogic using gaizka's version of authlogic_openid which I found on Github since pelle's original addition of the feature seemed to cause issues.
http://github.com/gaizka/authlogic%5Fopenid
http://stackoverflow.com/questions/1476953/using-authlogic-to-auto-create-users-bypassing-explicit-user-registeration
This one works fine however when using the auto_register feature it ignores my options for authlogic such as retrieving the email from the openid provider... any ideas what I'm doing wrong?
Hhere's the example:
http://big-glow-mama.heroku.com/
http://github.com/holden/authlogic_openid_selector_example/tree/with-facebook/
You can see the difference if you register vs. login...
#user.rb
class User < ActiveRecord::Base
acts_as_authentic do |c|
c.validate_login_field = false
# optional, but if a user registers by openid, he should at least share his email-address with the app
c.validate_email_field = false
# fetch email by ax
c.openid_required_fields = [:email,"http://axschema.org/contact/email"]
#c.required_fields = ["http://axschema.org/contact/email"]
# fetch email by sreg
#c.optional_fields = ["email"]
end
#private method to deal with emails goes here
end
#UserSession.rb
class UserSession < Authlogic::Session::Base
auto_register
logout_on_timeout true
end
Using a rake task to import data into a database: file as follows
namespace :db do
desc "load imported data from csv"
task :load_csv_data => :environment do
require 'fastercsv'
require 'chronic'
FasterCSV.foreach("input.csv", :headers => true) do |row|
Trade.create(
:name => row[0],
:type => row[4],
:price => row[6].to_f,
:volume => row[7].to_i,
:bidprice => row[10].to_f,
:bidsize => row[11].to_i,
:askprice => row[14].to_f,
:asksize => row[15].to_i
)
end
end
end
When attempting to use this, with the right CSV files and the other elements in place, it will say Don't know how to build task 'db:import_csv_data'
I know this structure works because I've tested it, I'm just trying to get it to convert to the new values on the fly.
Suggestions?
I'm working on a project to develop a cross-browser testing web app. Simply put, I'm tired of having to maintain multiple browsers on the same system and IE in VMware solely for the purpose of testing. Does anyone know if there is any way to change the render kit programmatically? For example, if I insert a URL, I would be able to load the URL and switch the browser render within a frame of some assortment. I am experienced with PHP, JS, and RoR if there is a solution using any of those.
Thank you!
John
I'm making a user administration page. For the system I'm creating, users need to be approved. Sometimes, there will be many users to approve, so I'd like to make that easy. I'm storing this as a boolean column called approved.
I remembered the Edit Multiple Individually Railscast and thought it would be a great fit. However, I'm running into problems which I traced back to ActiveRecord::Base#update.
update works fine in this example:
>> User.all.map(&:username)
=> ["ben", "fred"]
>> h = {"1"=>{'username'=>'benjamin'}, "2"=>{"username"=>'frederick'}}
=> {"1"=>{"username"=>"benjamin"}, "2"=>{"username"=>"frederick"}}
>> User.update(h.keys, h.values)
=> ...
>> User.all.map(&:username)
=> ["benjamin", "frederick"]
But not this one:
>> User.all.map(&:approved)
=> [true, nil]
>> h = {"1"=>{'approved'=>'1'}, "2"=>{'approved'=>'1'}}
>> User.update(h.keys, h.values)
=> ...
>> User.all.map(&:approved)
=> [true, nil]
Chaging from '1' to true didn't make a difference when I tested.
What am I doing wrong?
So ive got a ActionMailer mailer
class ReportMailer < ActionMailer::Base
def notify_doctor_of_updated_document(document)
recipients document.user.email_id
from "(removed for privacy)"
subject "Document #{document.document_number} has been updated and saved as #{document.status}"
sent_on Time.now
body :document => document
end
end
and the view is
Document
<%= @document.class %>
but when running
>> d = Document.last
=> #<Document id: "fff52d70-7ba2-11de-9b70-001ec9e252ed", document_number: "ABCD1234", procedures_count: 0, user_id: "630", created_at: "2009-07-28 18:18:07", updated_at: "2009-08-30 20:59:41", active: false, facility_id: 94157, status: "incomplete", staff_id: nil, transcriptionist_id: nil, job_length: nil, work_type: nil, transcription_date: nil, non_trans_edit_date: nil, pervasync_flag: true, old_id: nil>
>> ReportMailer.deliver_notify_doctor_of_updated_document(d)
=> #<TMail::Mail port=#<TMail::StringPort:id=0x8185326c> bodyport=#<TMail::StringPort:id=0x8184d6b4>>
from the console this is printed in the log
Sent mail to (removed for privacy)
Date: Tue, 11 May 2010 20:45:14 -0500
From: (removed for privacy)
To: (removed for privacy)
Subject: Document ABCD1234 has been updated and saved as incomplete
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary=mimepart_4bea082ab4ae8_aa4800b81ac13f5
--mimepart_4bea082ab4ae8_aa4800b81ac13f5
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: Quoted-printable
Content-Disposition: inline
Document
NilClass=
--mimepart_4bea082ab4ae8_aa4800b81ac13f5--
I want to make a simple examing application on RoR 2.3.
The problem area is to make an exam_session in a one form with only one submit action. For the exam session there are selected some number of questions from the question pool in random order. For these questions there are selected some number of alternatives (to check is this a single answer question or multi answer question I use the number of correct alternatives: if only 1 - single, 1 - multi. Radiobuttons or checkboxes in form to answer depends on it). I have models:
Questions ---< Alternative and ExamSession.
I think there must be has_many :through relations between ExamSession and Questions and has_many :through relation between the intermediate table (for example QuestionsExamSession) and Alternative to point what alternatives are answers of the student on this Question.
So the questions are:
Is this scheme is too complicated
and there is a way to do it simple
and clear?
Is there any way to organize models
in such a way to make the form I
want to work?
How do I make an HTTP GET request with parameters in Ruby?
It's easy to do when you're POSTing:
require 'net/http'
require 'uri'
HTTP.post_form URI.parse('http://www.example.com/search.cgi'),
{ "q" => "ruby", "max" => "50" }
But I see now way of passing GET parameters as a hash using net/http.
I have some difficulty to extract the total price (css selector = '.total') from the flight result.
http://www.momondo.com/multicity/?Search=true&TripType=oneway&SegNo=1&SO0=KUL&SD0=KBR&SDP0=31-12-2012&AD=2&CA=0,0&DO=false&NA=false#Search=true&TripType=oneway&SegNo=1&SO0=KUL&SD0=KBR&SDP0=31-12-2012&AD=2&CA=0,0&DO=false&NA=false
I get the error "undefined method `text' for nil:NilClass nokogiri ".
My code
desc "Fetch product prices"
task :fetch_details => :environment do
require 'nokogiri'
require 'open-uri'
include ERB::Util
OneWayFlight.find_all_by_money(nil).each do |flight|
url = "http://www.momondo.com/multicity/Search=true&TripType=oneway&SegNo=1&SO0=KUL&SD0=KBR&SDP0=31-12-2012&AD=2&CA=0,0&DO=false&NA=false#Search=true&TripType=oneway&SegNo=1&SO0=KUL&SD0=KBR&SDP0=31-12-2012&AD=2&CA=0,0&DO=false&NA=false"
doc = Nokogiri::HTML(open(url))
price = doc.at_css(".total").text[/[0-9\.]+/]
flight.update_attribute(:price, price)
end
end
Hi guys, I'm trying to install feedzirra. When i install curb on my netbeans i get following errors.
Building native extensions. This could take a while...
ERROR: Error installing curb-0.7.6.gem:
ERROR: Failed to build gem native extension.
"C:/Program Files/NetBeans 6.9 RC2/ruby/jruby-1.5.0/bin/jruby.bat.exe" extconf.rb
'"C:/Program Files/NetBeans 6.9 RC2/ruby/jruby-1.5.0/bin/jruby.bat.exe"' is not recognized as an internal or external command,
operable program or batch file.
Gem files will remain installed in C:/Program Files/NetBeans 6.9 RC2/ruby/jruby-1.5.0/lib/ruby/gems/1.8/gems/curb-0.7.6 for inspection.
Results logged to C:/Program Files/NetBeans 6.9 RC2/ruby/jruby-1.5.0/lib/ruby/gems/1.8/gems/curb-0.7.6/ext/gem_make.out
Any ideas how I can get this to work? Or did you know very fast feed parser gem?
I'm trying to add the user_id to a nested attribute that gets built by a parent controller but it doesn't seem to have the desired effect?
Ie. I have a model called Place.rb which accepts_nested_attributes_for :reviews
The nested attribute works fine and I build it inside the Places controller like so...
@review = @place.reviews.build(:user_id => current_user.id)
I was previously adding the user thru the form, but would like to do it thru the controller so that it only adds the user_id on creation, as it might get updated by someone else and i don't want the update changing the user_id...
old way which works:
<%= e.label :content, "Review" %><br />
<%= e.text_area :content, :rows => 20, :class => 'jquery_ckeditor' %><br />
<%= e.hidden_field :user_id, :value => current_user.id %>
but thru the controller the build method with options has no effect? Any ideas? Can I not do this thru the build?
I have an after_find callback in a model, but I need to disable it in a particular controller action e.g.
def index
@people = People.find(:all) # do something here to disable after_find()?
end
def show
@people = People.find(:all) # after_find() should still be called here!
end
What is the best way to do it?
Can I pass something in to .find to disable all/particular callbacks?
Can I somehow get the controller name in the model and not execute the callback based on the controller name (I don't like this)..?
Help!
I have installed the gem 'simple_uuid' but nothing seems to be working.
Using irb and running the following:
require 'rubygems'
require 'simple_uuid'
is fine, both return true. But running the following:
// Class added by simple_uuid
UUID.new
returns
NameError: uninitialized constant UUID
from (irb):3
from :0
I'm a ruby newbie, so don't assume much in the answers. Thanks.
I am trying send user profile images from a client to the server using ActiveResource.
Is there a gem/plugin that adds Multipart support to ActiveResource?
My question is similar to this one http://stackoverflow.com/questions/1342761/how-to-skip-activerecord-callbacks but instead of AR I'm using Mongoid, It seems like that isn't implemented yet in the current version of Mongoid, so I'd like to know what should be an elegant solution to implement it. (if necessary).
Hi,
i implementing a products catalog, that looks, like this:
group 1
subgroup 1
subgroup 2
item 1
item 2
...
item n
...
subgroup n
group 2
subgroup 1
...
subgroup n
group 3
...
group n
The Models:
class CatalogGroup < ActiveRecord::Base
has_many: catalog_items
has_many :catalog_items_all, :class_name => "CatalogItem", :foreign_key => "catalog_root_group_id"
end
class CatalogItem < ActiveRecord::Base
belongs_to :catalog_group
belongs_to :catalog_root_group, :class_name => "CatalogGroup"
end
Migrations:
class CreateCatalogItems < ActiveRecord::Migration
def self.up
create_table :catalog_items do |t|
t.integer :catalog_group_id
t.integer :catalog_root_group_id
t.string :code
t.timestamps
end
end
For convenience, i referenced each CatalogItem to it's top-most CatalogGroup and named this association "catalog_root_group".
This will give us the simple implementation of search request, like "show me all items in group 1".
We will have a deal only with CatalogModel.catalog_root_group
The problem is - this association does't work. I always get "catalog_root_group" equals to nil
Also, i have tried to overcome the using of reference to root group ("catalog_root_group"), but i cannot construct appropriate search request in ruby ...
Do you know, how to do it ?
I want to log into https://www.t-mobile.com/ programmatically. My first idea was to use Mechanize to submit the login form:
However, it turns out that this isn't even a real form. Instead, when you click "Log in" some javascript grabs the values of the fields, creates a new form dynamically, and submits it.
"Log in" button HTML:
<button onclick="handleLogin(); return false;" class="btnBlue" id="myTMobile-login"><span>Log in</span></button>
The handleLogin() function:
function handleLogin() {
if (ValidateMsisdnPassword()) { // client-side form validation logic
var a = document.createElement("FORM");
a.name = "form1";
a.method = "POST";
a.action = mytmoUrl; // defined elsewhere as https://my.t-mobile.com/Login/LoginController.aspx
var c = document.createElement("INPUT");
c.type = "HIDDEN";
c.value = document.getElementById("myTMobile-phone").value; // the value of the phone number input field
c.name = "txtMSISDN";
a.appendChild(c);
var b = document.createElement("INPUT");
b.type = "HIDDEN";
b.value = document.getElementById("myTMobile-password").value; // the value of the password input field
b.name = "txtPassword";
a.appendChild(b);
document.body.appendChild(a);
a.submit();
return true
} else {
return false
}
}
I could simulate this form submission by POSTing the form data to https://my.t-mobile.com/Login/LoginController.aspx with Net::HTTP#post_form, but I don't know how to get the resultant cookie into Mechanize so I can continue to scrape the UI available when I'm logged in.
Any ideas?
I need to be able to create a UserSession without having the decrypted password.
How do I go about doing this?
My current workaround is:
In user.rb
def valid_crypted_or_non_crypted_password?(password)
valid_password?(password) || password == crypted_password
end
In user_session.rb
verify_password_method :valid_crypted_or_non_crypted_password?
To login
UserSession.create(:login => u.login, :password => u.crypted_password)
Is there a nicer way to do this?