undefined method `with_scope' when trying to create new user - ruby-on-rails

I encounter a problem when trying to create a new user .
When I click on create,
undefined method `with_scope' for #
this shows up.
#user.timezonepref = User.find(#user.parent_id).timezonepref
if #user.save
The error console shows that the problem is in the line 'if #user.save'
I don't know why and when I grep for 'with_scope' under the whole folder , I don't see such function exists in any file.
And I also tried to drop, and re-create the whole database. But it is still not working.

The with_scope is an ActiveRecord method. You will not find it in your source code. Go to Rails console and reproduce the problem. You can also do #user.errors.full_messsages to check for error messages.

Related

Rails Console 'helper' and 'app' Appear Incomplete

Using ruby 2.3.0 and rails 4.2.5.1, I'm trying to figure some things
out using the rails console. I have several instances where app or helper seem like they have a method I want, but I often end up with the NoMethodError message. This happens even in a brand-new application where I've edited nothing and given no special options to the rails new command. For instance:
irb(main):015:0* helper.timez
... here I hit TAB to get:
irb(main):015:0* helper.timezone
... and hit ENTER, only to find:
NoMethodError: undefined method `timezone' for #<ActionView::Base:0xc662b80>
Why would tab-expansion in the console expand to methods that don't
exist? More importantly, if they're supposed to be there, why aren't
they? What can I be doing wrong?

NoMethodError when creating new user in rails

So when I submit all the info to create a new user: i get this error:
NoMethodError in UsersController#create
undefined method `sign_in' for #
I googled for it first and found answers where I was supposed to create a sessions_helper.rb file and include it in application.rb , did it all and when I refreshed after each step, it seemed to work. But now when I reloaded the page from the start again, I got the same error again.
Veske showed me his code: https://gist.github.com/Veske/7536022
You have to define your method in the SessionHelper, it is not going to automatically be made for you :)
You need to create a sign_in method in at least the SessionsHelper class.
If you'd like to use the devise gem for users creation/authentication, you'll have that method available in your code directly.

Can't create users in rails when using authlogic because of cookies

So, I have a standard rails 3 app with authlogic. If I'm not in the browser (in the console or in the test environment), I can't create user models.
For example:
I have this code either in a rspec test or in my console:
user = User.create(...user attributes...)
And I get this error:
NoMethodError: undefined method `cookies' for main:Object
I've looked all over the internet and can't figure this out. Any help would be greatly appreciated.
EDIT:
So, I looked around some more and found in the documentation to do this:
include Authlogic::TestCase
but then I get this error:
uninitialized constant Authlogic::TestCase
I had this same exact problem. Where in your application did you put the following line:
Authlogic::Session::Base.controller = Authlogic::ControllerAdapters::RailsAdapter.new(self)
I ran into this error when I placed the line in either the environment.rb file or within a file within my initializer folder.
I eliminated the problem when I placed the line in my ApplicationController instead.

Rails attribute working in console, not in app

I ran a migration on an Image model to add the column Position.
The schema is updated, the column has actually been added to the database, and is accessible through Rails console. I'm even calling an order by clause using that column in ActiveAdmin, and that doesn't grumble .
However when trying to access that attribute in the app, I'm presented with unknown attribute errors.
When trying to display the column in an ActiveAdmin index view, I get:
undefined method `position' for #<Image:0x007f8a3429be98>
It (position) has been added to attr_accessible too.
I've also run:
Image.connection.schema_cache.clear!
Image.reset_column_information
and that hasn't helped either.
Rails 3.2.12
After some searching and trying I was able to reproduce the error it was triggered by a before filter.
This post led me to the solution:
Undefined method "reorder" for #<Array:0xbc38600> using ActiveAdmin
when it helped please upvote the other comment.

NoMethodError in rails

The extracted source is below :
Showing /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/templates/rescues/diagnostics.erb where line # raised:
private method `gsub' called for #<NoMethodError: undefined method `closed?' for nil:NilClass>
Extracted source (around line #):
RAILS_ROOT: /home/sharath/Desktop/RORWorkspace/ITPLOW1
It was working before installing Sunspot: A Solr-Powered Search Engine for Ruby.
I am working in Ubuntu 10.04.
I'd need to see the full stacktrace to be sure, but this is actually probably an unhelpful HTTP connection error message bubbling up out of RSolr (the library the Sunspot uses for the low-level Solr connection). Is Solr running (i.e., did you run rake sunspot:solr:start)? Can you access http://localhost:8982/solr/admin ?
What's probably happening is you're attempting to do a substitution on some variable which you thought you were initializing, but neglected to give a real value.
For instance, if you had a form where for a Message and one of the the properties you want is the content, you would normally retrieve that information in the controller with
params[:message][:content]
And if you wanted to filter it, you would do something like
params[:message][:content].gsub(/<[^>]*>/,"")
But if the user didn't enter anything into the content field, the params[:message][:content] variable wouldn't be set. Therefore it's null and you're attempting to do nil.gsub

Resources