ruby-on-rails,ruby,railstutorial.org
I think the methods are named poorly. First of all I would pull the check for activated? into a guard clause in the User class since a non-active user can never be authenticated in my opinion: class User < ActiveRevord::Base # ... def authenticated?(...) return false unless activated? # ......
ruby-on-rails,ruby-on-rails-4,testing,rspec,railstutorial.org
You forgot to assign the title: assign(:user, user) assign(:title, user.name) ...
ruby-on-rails,railstutorial.org
The problem was that I had users in the database with the same email before the migration. db:reset solved everything
after a good nights sleep I realized it was likely due to a database error. Low and behold my database had a capitalized email and my controller submits a downcased email. Solved....
ruby,ruby-on-rails-4,railstutorial.org,will-paginate,minitest
Had a typo in my app/views/users/_users.html.erb, fixing it helped me pass the test. Right code is as - <li> <%= gravatar_for user, size: 50 %> <%= link_to user.name, user %> <% if current_user.admin? && !current_user?(user) %> | <%= link_to "delete", user, method: :delete, data: { confirm: "You sure?" } %>...
ruby-on-rails,ruby,rspec,railstutorial.org
If you're having a hard time including that method, you can try including it directly on your spec. require 'rails_helper' ... describe "page" do it { should have_content("Update your profile") } it { should have_title("Edit user") } it { should have_link('change', href: 'http://gravatar.com/emails') } end .... private def sign_in(user, options={})...
ruby-on-rails,ruby,heroku,railstutorial.org
If your user is not found (eg there isn't a user with the given email)... what happens when you try to check the expiration of it? Hint: look at what you do in valid_user for an example of what you should do in check_expiration...
ruby-on-rails,ruby,ruby-on-rails-3,ruby-on-rails-4,railstutorial.org
Theoretically, yes, practically, no. Sure, you can fire up a local web server and write code, but you obviously don't want to write everything yourself, you want to take advantage of ruby's gem package system. This will, obviously require an internet connection.
ruby-on-rails,ruby,railstutorial.org,arel,cloud9-ide
An update to the Arel gem broke migrations in Rails 4 beta. See here for details. The tutorial has already been updated with the fix.
ruby-on-rails,ruby-on-rails-4,railstutorial.org
I more or less answer my own question in an answer for someone else's question: How to dynamicly generate secret tokens in Rails 4.1 with secrets.yml?
ruby-on-rails,railstutorial.org
Understanding errors First of all, it's important that you learn to read & understand error messages properly: wrong number of arguments (2 for 1) for `asset-path` (in /app/assets/stylesheets/bootstrap_and_overrides.css.scss:1) This basically says, there are 2 arguments for the asset-path helper, but only 1 is expected. It does not know what to...
ruby-on-rails,ruby-on-rails-4,railstutorial.org
I'm posting here for completeness, but I was able to find my own answer. Here it is: Do the redirection options get lost whenever we call a via_redirect, and thus testing assert_redirected_to @user fails? Yes! Because of the way request_via_redirect works: # File actionpack/lib/action_dispatch/testing/integration.rb, line 92 def request_via_redirect(http_method, path, parameters...
ruby-on-rails,ruby,railstutorial.org
Based on what you've provided, the error you're getting is because there's already a user in your DB with the email address and you have a uniqueness validation on the :email field so you can't save another record with the same email. That's my best guess, if it's wrong, do...
ruby-on-rails,ruby,facebook,railstutorial.org,railscasts
This same error gave me a headache once. Check if the email you use for facebook is already in your database. If it's there then delete it and it should work.
ruby-on-rails,ruby,railstutorial.org
Your code is missing the setup method defined in Listing 10.29.
ruby-on-rails,ruby,railstutorial.org
Some of your records are nil, to identify them run the following code, you will get index values of those records <% @shops.each_with_index do |shop, index| %> <li> <% unless shop.blank? %> <%= link_to shop.name, shop %> <% else %> <%= "Record nil at " + index.to_s %> <% end...
ruby-on-rails,ruby,railstutorial.org
Looks like you have an error with your require statement. have you added the following code to your test_helper file? (Copied from https://www.railstutorial.org/book/static_pages#sec-advanced_testing_setup) ENV['RAILS_ENV'] ||= 'test' require File.expand_path('../../config/environment', __FILE__) require 'rails/test_help' require "minitest/reporters" Minitest::Reporters.use! class ActiveSupport::TestCase # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical # order. fixtures...
ruby-on-rails,ruby,railstutorial.org
Wow, lot's of debugging and confusion to discover a really simple problem: I wasn't logged in, and hadn't defined any kind of error message for those trying to access that page if they weren't logged in (hence the user.activation_token method triggering a Nil:NilClass error). Seems like a good example of...
ruby-on-rails-4,osx-mavericks,railstutorial.org,ruby-2.0
Your Rails -v and Ruby -v are correct for this tutorial. I can also see from the input that your gemfile has gem 'sqlite3', '1.3.8' in it. 1: Have you bundled? When was the last time you ran bundle update or bundle install? How did you go about uninstalling sqlite3?...
ruby-on-rails,ruby,ruby-on-rails-4,railstutorial.org
Thank you steve klein for helping me find the answer. The problem was in the sessions controller. if user && user.authenticate(params[:session][:passowrd]) A simple typo (password) was screwing me up....
ruby-on-rails,ruby,sqlite3,railstutorial.org
try migrating your DB to version=0 with command: rake db:migrate VERSION=0 and then run rake db:migrate ...
ruby-on-rails,railstutorial.org
This: <%= link_to "Settings", 'edit_user_path(current_user)' %> should become this: <%= link_to "Settings", edit_user_path(current_user) %> Your logs shows that app looks for /edit_user_path(current_user) because you send it as a string and normally you don't have this path. See line first of your logs Started GET "/edit_user_path(current_user)" it should be Started GET...
ruby-on-rails,ruby,cookies,session-cookies,railstutorial.org
I just made this mistake... TL;DR; remove remember user from sessions_controller.rb Take a look at Listing 8.34. You should find remember user in the session_controller.rb. Now in reference to the same file, take a look at Listing 8.49. The author makes a big deal about this line, but if you...
ruby-on-rails-4,controller,helper,railstutorial.org,gravatar
Following the advice found in this thread fixed the problem: Wrong number of arguments? Here is the code that should be in the User Helper: def gravatar_for(user) gravatar_id = Digest::MD5::hexdigest(user.email.downcase) gravatar_url = "https://secure.gravatar.com/avatar/#{gravatar_id}" image_tag(gravatar_url, alt: user.name, class: "gravatar") end ...
ruby-on-rails,ruby,rspec,railstutorial.org
That's a pretty old version of rspec. I'd suggest getting something newer (or you could edit your .rspec file to remove --warnings).
ruby-on-rails,sqlite3,railstutorial.org
Try changing these lines class CreateMicroposts < ActiveRecord::Migration # <==== convention def change create_table :microposts do |t| t.text :content t.references :user, index: true t.timestamps t.index [:user_id, :created_at] # <=== end end end ...
ruby-on-rails,railstutorial.org
I wouldn't add current password in the form, becuase You shouldn't really know the password in the first place, it's encrypted right? cause it should. If we ignore point (1), putting a plain password in the form can easily be inspected by any web inspector ( webdev tools, firebug, etc...
ruby-on-rails,ruby,activerecord,heroku,railstutorial.org
My problem was that git wasn't tracking any of the sessions files I had added, so they were on my local computer but not on github->heroku. I found this out by making a change only on sessions_helper, then committing to git only to get a message that there were no...
ruby-on-rails,forms,twitter-bootstrap,session,railstutorial.org
Remove the name attribute from every field in the form. Rails handles it for you and the way you are naming it is not creating the param that you expect.
ruby-on-rails,ruby,regex,railstutorial.org
The issue is at this line VALID_PHONE_NUMBER_REGEX = /^(\+\d{1,2}\s)?\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4}$/ it should be changed to VALID_PHONE_NUMBER_REGEX = /\A(\+\d{1,2}\s)?\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4}\z/ Personally, I would suggest to avoid trying to use a single regex to validate all those formats. Either group similar formats, and use different regexps, or normalize the input and validate a few...
ruby-on-rails,railstutorial.org
Are you typing 'class ApplicationController < ActionController::Base' into the console? What you are supposed to do is find your sample_app/app/controllers/application_controller.rb and add the new text inside that file. Then save and close the file. ...
ruby-on-rails,ruby,session-cookies,railstutorial.org
Restarting your server doesn't clear the session. And the browser still has a cookie, which is an id for a session. The browser sends the request, including the cookie. The server looks up the session by the id and finds a hash, which most likely identifies the user by their...
ruby-on-rails,railstutorial.org
Try this: 99.times do |n| name = Faker::Name.name email = "example-#{n+1}@railstutorial.org" password = "password" User.create!(name: name, email: email, password: password, password_confirmation: password, activated: true, activated_at: Time.zone.now) end #This is the missing end and your sytax error ...
ruby-on-rails,ruby,undefined,railstutorial.org
I suppose you are following the https://www.railstutorial.org You have a recurring undefined method 'current_user' error in [2, 3, 4, 5] Did you defined the current_user helper method as it should be done in your session_helper.rb ?...
ruby-on-rails,ruby,ruby-on-rails-3,ruby-on-rails-4,railstutorial.org
Your edit method is in your private block, move it above the private and it should work.
You are missing closing square brackets in your a[href] arguments. Your code should be as follows: require 'test_helper' class SiteLayoutTest < ActionDispatch::IntegrationTest test "layout links" do get root_path assert_template 'static_pages/home' assert_select "a[href=?]", root_path, count: 2 assert_select "a[href=?]", help_path assert_select "a[href=?]", about_path assert_select "a[href=?]", contact_path assert_select "a[href=?]", signup_path end end ...
ruby-on-rails,railstutorial.org,nomethoderror
Another migration is already named add_reset_to_users: You had already created the migration previously, as you noted, but this migration did not include the addition of the reset_sent_at column. At this point the easiest thing to do would be to create a new migration to add the missing column. rails...
ruby-on-rails,ruby-on-rails-4,railstutorial.org
admin = false is assignment, not condition checking. The following code should work def admin_toggle user = User.find(params[:id]) user.toggle!(:admin) flash[:success] = user.admin ? "User granted" : "User revoked" redirect_to users_url end after toggle, the user object gets updated, and admin attribute reflects the latest status Make sure you added route...
ruby-on-rails,ruby,debugging,railstutorial.org,cloud9-ide
AFIK, cloud9 IDE does not have a ruby debugger. According to their documentation, the debugger only support javascript/node.js apps: Note: Currently, only Javascript/Node.js applications can make use of the debugger. Hopefully, I'm wrong, and they've implemented it for ruby. ...
ruby-on-rails,heroku,railstutorial.org
So it's telling me that there's no such method as reset_digest, which I'm confused because I never actually call that. I call @user.create_reset_digest in def create, and I think that's the line that heroku logs are calling out No! @user.create_reset_digest calls the create_reset_digest in your user.rb which is actually...
ruby-on-rails,amazon-web-services,railstutorial.org,iam
For others in future, this answer helped me a lot. Go on Heroku, on your application, go to settings, hit Reveal Config Vars. Click on on Edit on the right side and enter your secrets there: S3_BUCKET: name of your bucket goes here S3_ACCESS_KEY: xxxxx S3_SECRET_KEY: xxxx On config/initializers/carrierwave.rb or...
ruby-on-rails,railstutorial.org
You need to include the sessions helper for it to be available in the controller/view layers. The application code that you linked to does include the sessions helper, it just does so in the application_controller.rb file as you can see here. By default, helper methods are only available to their...
ruby-on-rails,railstutorial.org,minitest,guard
2 tests, 2 assumptions, 0 failures, 0 errors, 0 skips means guard successfully ran 2 tests containing two assumptions (assertions). The messages in the debug log are telling you of missing dependencies. You could save yourself a big headache and use the free cloud 9 and heroku setup Hartl suggests,...
ruby-on-rails,ruby,railstutorial.org
Your log_out method is deleting the session before forgetting the user. This causes an error because forget takes current_user as a parameter and current_user uses the session to determine who the current user is: if (user_id = session[:user_id]) # This will attempt to assign user_id based on the value of...
ruby-on-rails-4,integration-testing,railstutorial.org,minitest
This is because @user was not initialized in your setup method. You initialize @admin and @non_admin, but not @user.
ruby-on-rails-4,railstutorial.org
I ended up naming 'Account' as 'User'. Everything works now. Still don't know what was wrong. Seems like there is some sort of rails 'magic' associated with the 'User' name.
ruby-on-rails,ruby,railstutorial.org
Blocks aren't really parameters - what shows up in the method signature is that this method captures the block passed to it in a proc, but that is really an implementation detail that is leaked to the outside world. For example if you define a method like this def foo(*args)...
ruby-on-rails,railstutorial.org
In your view file: <%= f.label :current_password %> <%= f.password_field :current_password %> Also make sure you permit the current_password parameter in your controller. I assumed current_password attr is already defined by has_secured_password....
ruby-on-rails,heroku,railstutorial.org
The "expected keyword_end" error means you have a syntax error in the specified file. You'll see this a lot, especially in your test suite; get cozy with it. Go through the file with a fine-tooth comb and mentally match up each { with its } and each do with its...
ruby-on-rails,ruby,heroku,railstutorial.org
My problem was that git wasn't tracking any of the sessions files I had added, so they were on my local computer but not on github->heroku. I found this out by making a change only on sessions_helper, then committing to git only to get a message that there were no...
ruby-on-rails,railstutorial.org
If you use somekind of specific authentication tools like Devise for ex. then I suggest implementing authorization solution with cancancan gem. You have a specific ability file there under your models directory where you can declare access-rights for different user roles. Makes your future code much cleaner and easier to...
ruby-on-rails,testing,tdd,railstutorial.org,minitest
So, I kept following the tutorial, and in the next chapter (Chapter 4), at some point, we create the full_title helper and remove the <% provide(:title, "Home") %> from the views. I am not sure how, but this solved the problem and made the tests to pass: 11:49:36 - INFO...
ruby-on-rails-4,rspec,railstutorial.org,ruby-2.0,rspec3
The have_selector matcher is provided by Capybara. Add that to your Gemfile.
ruby-on-rails-4,railstutorial.org
I did run bundle install while I was trying to install rcov (Rubymine was complaining about its lack). The installation failed as rcov is not available for my version of rails. That's fine. The really bizarre thing is that afterwards I re-ran the tests and everything worked. There was no...
ruby-on-rails-4,actionmailer,railstutorial.org
You are calling UserMailer.password_reset(user) and passing in the user but your password_reset method does not take an argument. So either you will need to change your password_reset to take a user (and do something with it) def password_reset(user) #do something with the user, such as send to their email address...
ruby-on-rails,ruby,ruby-on-rails-4,heroku,railstutorial.org
Their is no such phone_field in rails, change it to text_field or number_field or telephone_field. <%= f.phone_field :phone, class: 'form-control' %> to <%= f.text_field :phone, class: 'form-control' %> or <%= f.telephone_field :phone, class: 'form-control' %> ...
ruby-on-rails,railstutorial.org
Try like that:- <p>Project: <%= @work.project.present? ? @work.project.name : "" %></p> Here @work doesnot have any project, so the project of that @work is nil. So due to @work.project.name, it is throwing that error. The relation should be like that:- class Project < ActiveRecord::Base has_many :works end class Work <...
ruby-on-rails,ruby,ruby-on-rails-3,railstutorial.org
You should not use sudo for installing gems. Use rbenv.
I don't know why, but i cant view book from Europe(I tried from Serbia, France and England). I entered site when i established VPN connection with server in Chicago USA.
ruby-on-rails,capistrano,spree,railstutorial.org,digital-ocean
You've got a Cannot allocate memory error. That means not enough RAM for bundler on your deploying machine. You can add swap partition to do this, or create a DO droplet with bigger RAM space. Good tutorial about adding a swap to DO droplet https://www.digitalocean.com/community/tutorials/how-to-add-swap-on-ubuntu-12-04...
ruby-on-rails,ruby,railstutorial.org
Here is a little more explanation for why you are getting a syntax error: in ruby, parentheses are not required around method calls, but when you do choose to include them, the beginning parenthesis must have no space between itself and the method name, just like java, C, C++, and...
ruby-on-rails-4,railstutorial.org
time_ago_in_words will not add ago word.You should be adding it maually. This should work. <li> <span class="content"><%= micropost.content %></span> <span class="timestamp"> Posted <%= time_ago_in_words(micropost.created_at) %> ago. #here </span> </li> ...
ruby-on-rails,ruby,ruby-on-rails-4,routes,railstutorial.org
get 'account_activations/update_email/:id' => 'account_activations#update_email', as: 'update_email'. Here I get an error saying missing required keys: [:id]. You are getting this error because in your config/routes.rb file, you are saying get 'account_activations/update_email/:id, and that makes it necessary to send an id whenever you would trigger this route. And you when...
ruby-on-rails,ruby,heroku,railstutorial.org,puma
Prakash Murthy pretty much answered this for me - thanks. At first I tried to re-type the contents of the puma.rb - it didn't work. Then I decided to try deleting puma.rb altogether, and typing it from scratch in a new file. Weirdly, it worked! My text editor is Atom....