Does anybody know of a plug-and-play login system that supports existing logins like Google and OpenID?
I am looking to implement something similar to that of Stack Overflows.
Thanks!
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.
Does anyone know how to workarounds Heroku's limitations on writing to the theme files for the Typo blogging platform? I'd like to take advantage of the theming capabilities right from the browser. If any theme's stylesheet is changed I get the error message "Unable to write file" in addition to the fact that any theme being changed to one that is not the default causes the page to lose all styling and is displayed in plain text.
I followed this (awesome) blog entry to get it up and working.
Hi There,
Continuing with my adventure to convert COBOL to a Ruby program, I have to convert a decimal digit to a comp-3/packed decimal format. Anyone know of a simple Ruby script or gem that does this?
Berns
I'm using the friendly_id gem. I also have my routes nested:
# config/routes.rb
map.resources :users do |user|
user.resources :events
end
So I have URLs like /users/nfm/events/birthday-2009.
In my models, I want the event title to be scoped to the username, so that both nfm and mrmagoo can have events birthday-2009 without them being slugged.
# app/models/event.rb
def Event < ActiveRecord::Base
has_friendly_id :title, :use_slug => true, :scope => :user
belongs_to :user
...
end
I'm also using has_friendly_id :username in my User model.
However, in my controller, I'm only pulling out events pertinent to the user who is logged in (current_user):
def EventsController < ApplicationController
def show
@event = current_user.events.find(params[:id])
end
...
end
This doesn't work; I get the error ActiveRecord::RecordNotFound; expected scope but got none.
# This works
@event = current_user.events.find(params[:id], :scope => 'nfm')
# This doesn't work, even though User has_friendly_id, so current_user.to_param _should_ return "nfm"
@event = current_user.events.find(params[:id], :scope => current_user)
# But this does work!
@event = current_user.events.find(params[:id], :scope => current_user.to_param)
SO, why do I need to explicitly specify :scope if I'm restricting it to current_user.events anyway? And why does current_user.to_param need to be called explicitly? Can I override this?
read/write_attribute is a great way to enhance default accessors generated by ActiveRecord. Like this for example:
def price
read_attribute(:price) or "This item is priceless and you are by the way #{User.current.login}"
end
The same however does not seem to be working with associations.
Demonstration:
class Product < ActiveRecord::Base
has_and_belongs_to_many :stores
end
Then
>> a = Product.first
=> #<Product id: 1, name: "awesome product", created_at: "2010-05-07 12:11:00", updated_at: "2010-05-07 12:11:00">
>> a.stores
=> [#<Store id: 1, name: "ikea", created_at: "2010-05-07 12:11:28", updated_at: "2010-05-07 12:11:28">]
>> a.read_attribute(:stores)
=> nil
>>
So, is there some sort of read/write_association? Or, if not, is there a reason not to have one?
I am using Factory Girl but like the machinist syntax. So I wonder, if there is any way creating a named blueprint for class, so that I can have something like that:
User.blueprint(:no_discount_user) do
admin false
hashed_password "226bc1eca359a09f5f1b96e26efeb4bb1aeae383"
is_trader false
name "foolish"
salt "21746899800.223524289203464"
end
User.blueprint(:discount_user) do
admin false
hashed_password "226bc1eca359a09f5f1b96e26efeb4bb1aeae383"
is_trader true
name "deadbeef"
salt "21746899800.223524289203464"
discount_rate { DiscountRate.make(:rate => 20.00) }
end
DiscountRate.blueprint do
rate {10}
not_before ...
not_after ...
end
Is there a way making factory_girl with machinist syntax acting like that? I did not find one. Help appreciated.
Thx in advance
Jason
I have developed a blog application of sorts that I am trying to allow other users to take advantage of (for free and mostly for family). I wondering if the authentication I have set up will allow for such a thing. Here is the scenario.
Currently the application allows for users to sign up for an account and when they do so they can create blog posts and organize those posts via tags. The application displays no data publicly (another words, you have to login to see anything). To gain access you have to create an account and even after you do, you cannot see anyone else's information as the applications filters using the current_user method and displays in the /posts/index.html.erb page. This would be great if a user only wanted to blog and share it with themselves, not really what I am looking for.
My question has two parts (hopefully I won't make anyone mad by not putting these into two questions)
Is it possible for a particular users data to live at www.myapplication.com/user without moving everything to the /user/show.html.erb file?
Is it possible to make some of that information (living at the URL) public but still require login for create and destroy actions.
Essentially, exactly like twitter. I am just curious if I can get from where I am (using the current_user methods across controllers to display in /posts/index.html.erb) to where I want to be. My fear is that I have to redesign the app such that the user data lives in the /user/show.html.erb page.
Thoughts?
I have developed a blog application of sorts that I am trying to allow other users to take advantage of (for free and mostly for family). I wondering if the authentication I have set up will allow for such a thing. Here is the scenario.
Currently the application allows for users to sign up for an account and when they do so they can create blog posts and organize those posts via tags. The application displays no data publicly (another words, you have to login to see anything). To gain access you have to create an account and even after you do, you cannot see anyone else's information as the applications filters using the current_user method and displays in the /posts/index.html.erb page. This would be great if a user only wanted to blog and share it with themselves, not really what I am looking for.
My question has two parts (hopefully I won't make anyone mad by not putting these into two questions)
Is it possible for a particular users data to live at www.myapplication.com/user without moving everything to the /user/show.html.erb file?
Is it possible to make some of that information (living at the URL) public but still require login for create and destroy actions.
Essentially, exactly like twitter. I am just curious if I can get from where I am (using the current_user methods across controllers to display in /posts/index.html.erb) to where I want to be. My fear is that I have to redesign the app such that the user data lives in the /user/show.html.erb page.
Thoughts?
UPDATE:
I am using Clearance for authentication by Thoughtbot. I wonder if there is something I can set in the vendored gem path to represent the /posts/index.html.erb code as the /user/id code and replace id with the user name.
In linking a sports event to two teams, at first this seemed to make sense:
events
- id:integer
- integer:home_team_id
- integer:away_team_id
teams
- integer:id
- string:name
However I am troubled by how I would link that up in the active record model:
class Event
belongs_to :home_team, :class_name => 'Team', :foreign_key => "home_team_id"
belongs_to :away_team, :class_name => 'Team', :foreign_key => "away_team_id"
end
Is that the best solution?
In an answer to a similar question I was pointed to single table inheritance, and then later found polymorphic associations. Neither of which seemed to fit this association. Perhaps I am looking at this wrong, but I see no need to subclass a team into home and away teams since the distinction is only in where the game is played. If I did go with single table inheritance I wouldn't want each team to belong_to an event so would this work?
# app/models/event.rb
class Event < ActiveRecord::Base
belongs_to :home_team
belongs_to :away_team
end
# app/models/team.rb
class Team < ActiveRecord::Base
has_many :teams
end
# app/models/home_team.rb
class HomeTeam < Team
end
# app/models/away_team.rb
class AwayTeam < Team
end
I thought also about a has_many through association but that seems two much as I will only ever need two teams, but those two teams don't belong to any one event.
event_teams
- integer:event_id
- integer:team_id
- boolean:is_home
Is there a cleaner more semantic way for making these associations in active record? or is one of these solutions the best choice?
Thanks
I am trying to test facebook api calls with cucumber. Here is the code.
# app/controller/facebook_users_controller.rb
class FacebookUsersController < ApplicationController
def create
fb_user = facebook_session.user
user = User.new(:facebook_uid => fb_user.uid, :facebook_session_key => facebook_session.session_key
respond_to do |format|
if user.save
format.json { render :json => { :status => 'ok' }.to_json }
end
end
end
end
# features/steps/facebook_connect_step.rb
Given /^I am a facebook connected user$/ do
mock_session = Facebooker::MockSession.create
post('/facebook_user.json')
puts response.code
end
When I run the cucumber step for above step definition, I get a response code of 406 instead of 200. This happens in the cucumber test environment only and not in the browser(development/production).
I've been having almost the same issues as Victor Martin (you can see the questions asked here).
I've got declarative authorization working for just about everything that doesn't involve using conditionals. E.g.
has_permission_on :users, :to => [:edit, :update, :destroy] do
if_attribute :user => is { current_user }
end
Are there any common pitfalls with Declarative Authorization? I'm using authlogic and I'm suspicious the 'current_user' method in the application controller might be the source of the problem.
I'm wondering if theres a best practice for what I'm trying to accomplish...
First we have the model categories, categories, has_many posts.
Now lets say, users add posts.
Now, I have a page, that I want to display only the current user's posts by category.
Lets say we have the following categories: A, B, and C
User 1, has posted in Categories A and B.
In my view I have something like:
<% @categories.select {|cat| cat.posts.count > 0}.each do |category| %>
<%= category.name %><br/>
<% category.posts.select {|post| post.user == current_user}.each do |post| %>
<%= post.content %><br/>
<% end %>
<% end %>
For the most part its almost there. The issue is, it will still show an empty category if any posts have been entered in it at all (even if the current user has not input posts into that category.
So the question boils down to:
How do I make the following loop only count posts in the category from the current user?
<% @categories.select {|cat| cat.posts.count 0}.each do |category| %
Best,
Elliot
I've got a web app where I'd like to user FTS3 functionality of SQLite3.
I've got the SQLite3-ruby v1.2.5 gem installed. I'd like to have FTS3 support, and I know, due to trying to create an FTS3 table, that it doesn't come with it.
Do I need to compile the gem/sqlite3 myself in order to get this support? Is there a seprate gem I should be using?
I've written this class that returns feed updates, but am thinking it can be further improved. It's not glitchy or anything, but as a new ruby developer, I reckon it's always good to improve :-)
class FeedManager
attr_accessor :feed_object, :update, :new_entries
require 'feedtosis'
def initialize(feed_url)
@feed_object = Feedtosis::Client.new(feed_url)
fetch
end
def fetch
@feed_object.fetch
end
def update
@updates = fetch
end
def updated?
@updates.new_entries.count > 0 ? true : false
end
def new_entries
@updates.new_entries
end
end
As you can see, it's quite simple, but the things I'm seeing that aren't quite right are:
Whenever I call fetch via terminal, it prints a list with the updates, when it's really supposed return an object.
So as an example, in the terminal if I do something like:
client = Feedtosis::Client.new('http://stackoverflow.com/feeds')
result = client.fetch
I then get:
<Curl::Easy http://stackoverflow.com/feeds>
Which is exactly what I'd expect. However, when doing the same thing with "inniting" class with:
FeedManager.new("http://stackoverflow.com/feeds")
I'm getting the object returning as an array with all the items on the feed.
Sure I'm doing something wrong, so any help refactoring this class will he greatly appreciated.
Also, I'd like to see comments about my implementation, as well as any sort of comment to make it better would be welcome.
Thanks in advance
I'm trying to define a step to test the value of alt text of an image using capybara and the css selectors.
I wrote one for input values based on the readme examples:
Then /^I should see a value of "([^\"])" within the "([^\"])" input$/ do |input_value, input_id|
element_value = locate("input##{input_id}").value
element_value.should == input_value
end
But I can't figure this one out...something like:
Then /^I should see the alttext "([^\"]*)"$/ do | alt_text |
element_value = locate("img[alt]").value
Anyone know how I can locate the alt text value?
I have -- what I think -- is a simple question. Here's my code:
class Fruit < ActiveRecord::Base
end
class Apple < Fruit
end
class Kiwi < Fruit
end
Assume that I have all the STI setup correctly, and there are multiple types of Apple and Kiwi records in the table. From here...
fruits = Fruit.find(:all)
...how do I return an array of just Apples from the fruits array?
What is the proper way to register users automatically when they log in with openid?
I am using authlogic with an authlogic-oid gem (and an older version of openid_authentication).
The stuff I read online so far seems to be obsolete.
Does anyone know the proper way to do it with the new gem?
What I do now is:
options = params[:user_session] || {}
[:openid_identifier].each { |k| options[k] = params[k] if params[k] }
@user_session = UserSession.new(options)
@user_session.save do |result|
if result
flash[:notice] = "Login successful! (#{result.inspect})"
redirect_back_or_default account_url
else
render :action => :new
end
end
By the way, I don't see the Login Successful flash (but that is not that big of a deal).
As in the standart cycle:
- @goods.each do |good|
???
...to organize this (HAML):
.columns-wrapper
.column First good
.column Second good
.column Third good
.columns-wrapper
.column Fourth good
.column Fifth good
.column Sixth good
class Question < ActiveRecord::Base
belongs_to :author
end
class Author < ActiveRecord::Base
has_many :questions
end
When I find some questions, I usually need to get their authors at the same time, so I use:
Question.find(:all, :include=>:authors)
But I don't write the ":include" part everywhere. I hope I can define the "include" somewhere only once, and when I find questions, the author will be automaticly loaded. Is there any way to do this?
Whats the best way to enable users to log in with their email address OR their username? I am using warden + devise for authentication. I think it probably won't be too hard to do it but i guess i need some advice here on where to put all the stuff that is needed. Perhaps devise devise already provides this feature? like in the config/initializers/devise.rb you would write:
config.authentication_keys = [ :email, :username ]
To require both username AND email for signing in. But i really want to have only one field for both username and email and require only one of them. I'll just visualize that with some ASCII art, it should look something like this in the view:
Username or Email:
[____________________]
Password:
[____________________]
[Sign In]
I am using XMLRPC to get data from a Java server. I use HashMap as return value for a particular remote call. The server puts a long int into the HashMap (which is returned) along with other data. At the client end, which is ruby, I get all other data but for the long int. How can I get this data at the client?
I need to convert a Date object into a TimeWithZone object representing the beginning of that day in a given time zone.
The following approach works, but seems too convoluted as it requires me to convert the date to a string:
?> date = Date.parse("2010-02-17")
=> Wed, 17 Feb 2010
>> ActiveSupport::TimeZone['Eastern Time (US & Canada)'].parse(date.to_s)
=> Wed, 17 Feb 2010 00:00:00 EST -05:00
>> ActiveSupport::TimeZone['UTC'].parse(date.to_s)
=> Wed, 17 Feb 2010 00:00:00 UTC 00:00
Is there a better way I'm missing?
Sometimes an Twitter OAuth is successfully executed, but an unauthorized error is thrown. I get about 50 of these on a daily basis. It is worrying, because I have no idea how that might be reproduced.
What are the different cases where this error happens, and how can this be fixed or prevented?