undefined method `within' - ruby-on-rails-3

I followed the installation procedure of geokit-rails3, here is my conf :
Using rails (3.0.4)
Using activerecord (3.0.4)
Using geokit (1.5.0)
Using geokit-rails (1.1.4)
I get this error "undefined method `within' for #" when i try to query with the "within" method. (note that i am new to rails and maybe missing something obvious)
Here is my class definition :
class Snip < ActiveRecord::Base
belongs_to :user
acts_as_mappable :default_units => :kms,
:default_formula => :sphere,
:distance_field_name => :distance,
:lat_column_name => :latitude,
:lng_column_name => :longitude
end
In my controller i have :
#userLocation = GeoKit::LatLng.new(params[:lat],params[:lng])
#snips = Snip.within(params[:distance], :origin => #userLocation)
Here is what i added to my gemfile :
gem 'geokit', '>= 1.5.0'
gem 'geokit-rails', '1.1.4'
Do you have any idea why i get this error ?
Thanks in advance,
Vincent.

Your gemfile asks for geokit-rails, that's the Rails 2 version. You need to replace that with geokit-rails3

Related

ActiveRecord::AssociationTypeMismatch ruby 1.8 without using spork

I have models specs, controllers spec and request spec. When I run:
rspec spec
models spec are run first, then request and then when controller specs are run the specs for the first controller are OK, but the next fail. But when I run only the controller specs they all pass. I am with rails 3.0.9, ruby 1.8, factory_girl 2.2.0. I have
config.cache_classes = true
in test.rb and I can't change the version of ruby or factory_girl. Can someone help me?
UPDATE:
This is the error:
96) UsersController reset_password: as non-master_admin: does not reset a user's password
Failure/Error: let!(:user) { Factory(:admin_user) }
ActiveRecord::AssociationTypeMismatch:
AdminUser(#-630697398) expected, got MerchantUser(#-629918188)
# ./app/models/activity.rb:33:in `log'
# ./config/initializers/add_activity_logging.rb:8:in `_callback_after_759'
# ./spec/controllers/users_controller_spec.rb:8
in spec/controllers/users_controller_spec.rb:8:
let!(:user) { Factory(:admin_user) }
in activity.rb:33:
create(:user => user, :title => title, :changeable_id => changeable.id,
:changeable_type => changeable.class.to_s, :data => attributes)
also there is:
belongs_to :user, :class_name => 'AdminUser'
in the class AdminUser there isn't has_many activities but when I tried to add it I couldn't add it correctly I guess.
Thanks for the help
UPDATE:
AdminUser and MerchantUser are descendants of User
POSIBLE FIX
The line that gave error was actually:
admin_user = Factory(:tech_admin)
I replaced it with:
admin_user = FactoryGirl.build_stubbed(:tech_admin)
This way the file activity.rb is not reached
FINAL FIX
Apparently the problem was with Factory(:reseller). I replaced it with FactoryGirl.create(:reseller) and it everything work. Though now I am wondering and searching what is the difference between the two uses

How to configure sequence separator of friendly_id gem

I am using the friendly_id gem version 4.0.9 in Rails 3, and I want to change the default sequence separator from - to _.
I tried this but it doesn't work:
class Restaurant < ActiveRecord::Base
extend FriendlyId
friendly_id do |config|
config.base = :name
config.use :slugged
config.sequence_separator = "_"
end
.....
end
Taken from the gem's tests on GitHub:
friendly_id :name, :use => :slugged, :sequence_separator => "_"
Should work...
For Friendly_Id Gem 5.x with Rails 4.x
(Might also work with lower versions of Friendly_Id Gem or Rails)
Add the following method to the model file where you are using Friendly_Id to generate slugs-
def normalize_friendly_id(string)
super.gsub("-", "_")
end

undefined method `stringify_keys'

When I try to upload image using Paperclip gem I got this error:
NoMethodError (undefined method `stringify_keys' for <ActionDispatch::Http::UploadedFile:0x000000025387f0>)
class MenuItem < ActiveRecord::Base
has_one :image
end
class Image < ActiveRecord::Base
belongs_to :menu_item
has_attached_file :image, :styles => {
:large => "640x480",
:medium => "300x300",
:thumb => "100x100"
}
end
I've seen this error happen before, usually when people attempt to call update_attributes like this:
update_attributes(params[:image])
The call should actually be this:
update_attributes(:image => params[:image])
A bit of a shot in the dark, but if that's it I'm sure we'll all be impressed.
After struggling for a while in rails 3.2.2 I managed to solve this in this manner
(image = Image.new(image: params[:image])).save
update_attributes(image: image)
I just had this problem, and to clarify things a bit, update_attributes is different from update_attribute.
The following should work:
update_attributes(:image => params[:image])
or
update_attribute(:image, params[:image])
There you go! There are other issues with update_attributes related to attr_accesible, but either works.

Install recaptcha gem with exsisting devise gem with rubymine 3.1

What I've tried doing already: I've tried reading the documentation at github and getting it to work on Rubymine and I've managed to confuse myself with what is needed as far as controllers, and what is needed in the config folder. I've tried google and found some pretty good tutorials but their missing steps that I don't necessarily know to jump too.
What I'm trying to figure out: I want to be able use recaptcha in a login registration utlitizing the devise gem, I've already generated the pages for my devise login.
What I have so far:
I've installed and attached: devise 1.2.rc and recaptcha 0.3.1 I'm running Rubymine on windows xp. Ruby SDK 1.8.7-p302, with Rails 3.0.3
I've been to google and have my public and private keys
The next step tells me I'm supposed to add my keys to project/config/initializers/recaptcha.rb This is what is contained in that file:
Recaptcha.configure do |config|
config.public_key = 'myKey'
config.private_key = 'myKey'
end
Now I'm supposed to fix up my gemfile with:
gem 'recaptcha', :require => 'recaptcha/rails'
I also have my config/application.rb reading:
require 'rails/all'
require 'net/http'
I've also added to my External Libraries/[gem] devise/app/views/devise/registrations/new.html.erb the recaptcha tag:
<%= recaptcha_tags %>
<p><%= f.submit "Sign up" %></p>
Where I am running into issues (I think) is the
app/controllers/registrations_controller.rb and the config/routes.rb
I'm kinda of at a loss for what exactly goes into these files. Any help would be appreciated or a tutorial someone has written that walks me through this step by step would be very helpful. Thanks
Here's what I have done after Felix's post:
external libraries/app/controllers/devise/registrations_controller.rb
class Devise::RegistrationsController < Devise::RegistrationsController
def create
if verify_recaptcha then
super
else
build_resource
clean_up_passwords(resource)
flash[:notice] = 'Invalid Captcha'
render_with_scope :new
end
build_resource
if resource.save
if resource.active?
set_flash_message :notice, :signed_up
sign_in_and_redirect(resource_name, resource)
else
set_flash_message :notice, :inactive_signed_up, :reason => resource.inactive_message.to_s
expire_session_data_after_sign_in!
redirect_to after_inactive_sign_up_path_for(resource)
end
else
clean_up_passwords(resource)
render_with_scope :new
end
end
From Project/config/routes.rb:
devise_for :users, :controllers => {:registrations => 'registrations'}
This is the error that its spitting out:
ActionController::RoutingError (uninitialized constant RegistrationsController):
Rendered C:/Ruby/lib/ruby/gems/1.8/gems/actionpack-3.0.3/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (0.0ms) ..... any ideas?
For your routes, you can keep your normal devise routes except specifying your custom controller:
devise_for :users, :controllers => {:registrations => 'registrations'}
In the registrations_controller.rb, you want to subclass the Devise RegistrationsController and override the 'create' method:
class RegistrationsController < Devise::RegistrationsController
def create
if verify_recaptcha then
super
else
build_resource
clean_up_passwords(resource)
flash[:notice] = 'Invalid Captcha'
render_with_scope :new
end
end
end

Using Railslist, on rails3

I'm trying to modify railslist to work with Rails 3. I keep getting this error when trying to view /classifieds
TypeError (can't convert nil into
Array)
app/controller/classifieds_controller.rb:in
'index'
def index
#classifieds = Classified.paginate :page => params[:page], :order => "created_at DESC"
render :layout => 'main'
end
You need to use a pre-release version of will_paginate if you're using Rails 3. Put the following in your Gemfile in place of what you had for will_paginate before:
gem "will_paginate", "~> 3.0.pre2"