rspec error 'undefined method' valid? in my user_spec model - ruby on rails tutorial
Date : March 29 2020, 07:55 AM
will help you I get following error when running rspec: , I made a typo, misspelled valid
|
rails 4 - undefined method `valid?'
Date : March 29 2020, 07:55 AM
around this issue The query User.joins(:cars).where('cars.color' => "blue") returns an ActiveRecord::Relation instance. Check docs here. If you really want to operate over an instance (of User class), you must take a user from that collection, for example: @user = User.joins(:cars).where('cars.color' => "blue").first
|
Ruby on rails - Helper method - undefined method `log_in' in Ruby on rails
Date : March 29 2020, 07:55 AM
this one helps. You are missing the ApplicationController part here which includes the helper in the controller so its methods can be accessible directly: class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
include SessionsHelper
end
|
Rails NoMethodError: undefined method `valid?'
Date : March 29 2020, 07:55 AM
should help you out There's not a valid? method for an ActiveRecord collection. If you're trying to test that the last Ticket you created is valid, you can do something like assert @ticket.valid?. I think you might be doing a bit too much work in your setup method. You could try to just setup your User and Event model in the setup, and break the rest of what you described into different test blocks.
|
ruby on rails undefined method 'valid' when using update
Date : March 29 2020, 07:55 AM
I wish did fix the issue. ActiveRecord update(id, attributes) Updates an object (or multiple objects) and saves it to the database, if validations pass. The resulting object is returned whether the object was saved successfully to the database or not. def update
@user = User.find(params[:id]) //Find user
if @user.update(user_params) // Update user if validations pass
redirect_to "/users/#{@user.id}"
else
flash[:errors] = @user.errors.full_messages
redirect_to "/users/#{@user.id}/edit"
end
end
User.update(params[:id], user_params)
|