railstutorial.org

Add a JavaScript display to the Home page to count down from 140 characters. (Rails Tutorial, 2nd Ed, Chapter 10, Exercise 7)

泪湿孤枕 提交于 2019-12-02 23:17:43
This exercise was a bit tricky. Figured I'd post my solution to see if anyone did it differently or if there's anyone who knows a better way. I'm not sure on best practices for using the Asset Pipline .. for example, the correct order to put things in the application.js manifest file, or when to put things in lib versus app. I just put the following in lib to try getting it to work. From Michael Hartl's Rails Tutorial 2nd ed Chapter 10, Exercise 7: (challenging) Add a JavaScript display to the Home page to count down from 140 characters. First, I read this post about jQuery Twitter-like

$ bundle exec rake db:reset command raising couldn't drop db/development.sqlite3

二次信任 提交于 2019-12-02 22:23:14
I tried to run $ bundle exec rake db:reset and found the following on console Couldn't drop db/development.sqlite3 : #<Errno::EACCES: Permission denied - c:/sample_app/db/development.sqlite3> db/development.sqlite3 already exists -- create_table("users", {:force=>true}) -> 0.3940s -- add_index("users", ["email"], {:name=>"index_users_on_email", :unique=>true}) -> 0.1280s -- initialize_schema_migrations_table() -> 0.0010s -- assume_migrated_upto_version(20120419034627, ["c:/sample_app/db/migrate "]) -> 0.0040s How can I solve it? Edit I was following a tutorial and it tells me to run the above

Rails Tutorial: nokogiri-1.5.2 error on bundle install

不打扰是莪最后的温柔 提交于 2019-12-02 21:57:11
After working through the RVM setup, rspec and guard sections of chapter 3 of the Ruby on Rails Tutorial , whenever I run bundle install I get the following error dump: Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension. /usr/bin/ruby1.9.1 extconf.rb /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- mkmf (LoadError) from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require' from extconf.rb:5:in `<main>' Gem files will remain installed in /home/dan/.bundler/tmp/17577/gems/nokogiri-1.5.2 for inspection. Results logged

Do I need a “Users” controller when using Devise in Rails

痞子三分冷 提交于 2019-12-02 20:35:26
I am a Rails newbie. I am working on a small Rails4 project trying to improve my skills. I am loosely following M.Hartl's tutorial . As per the tutorial a custom user authentication is built. However I would like to use Devise for User authentication. Do I still need to have a Users controller as in the tutorial? In which cases should I use/not use a Users controller when already using Devise? Concerning the tutorial, do I just skip the controller generating part or do I have to map the actions to Devise? You only need a users controller if you want to manage users separately from the normal

Rails tutorial: undefined method

点点圈 提交于 2019-12-02 19:57:41
问题 I'm stuck (again!) at Chapter 9 (this time in section 9.2.2) of the Rails tutorial. I am getting bundle exec rspec spec/ ................................FFF........................ Failures: 1) Authentication authorization as wrong user submitting a GET request to the Users#edit action Failure/Error: before {sign_in user, no_capybara: true} NoMethodError: undefined method `new_remember_token' for #<User:0x007f8181815448> # ./spec/support/utilities.rb:13:in `sign_in' # ./spec/requests

RSpec test destroy method (Rails Tutorial 3.2 Ch. 9, Ex. 10)

元气小坏坏 提交于 2019-12-02 18:21:06
Note: I've read this question and the answer, but for some reason the code isn't working for me. (see below for the error I'm getting) Exercise 10 from Chapter 9 of the Rails Tutorial asks you to: Modify the destroy action [for users] to prevent admin users from destroying themselves. (Write a test first.) The tricky part here is testing it, because the application already hides the "delete" link for the current user, so you have to do the http request directly. I got the code working, and tested it by removing the piece of code that hides the delete link for the current user. Sure enough, if

How to solve the update bundler warning in rails when deploying to heroku?

纵饮孤独 提交于 2019-12-02 17:59:13
How do I solve the following warning? I updated my ruby version to 2.3.1 and rails version to 4.2.6. I get this warning when I push my app to heroku. remote: Cleaning up the bundler cache. remote: Warning: the running version of Bundler is older than the version that created the lockfile. We suggest you upgrade to the latest version of Bundler by running `gem install bundler`. remote: Removing mime-types-data (3.2016.0221) I removed the Gemfile.lock and ran bundle install and also tried to update the bundler but the warning never goes away . suramai@rails-tutorial:~/workspace/converse (master)

Confused about 'respond_to' vs 'respond_to?'

99封情书 提交于 2019-12-02 16:20:19
I am learning Rails with railstutorial.org, and I am confused about something: in this chapter the author tells us to do some testing in the console with the respond_to? method on a User object, and it works ok. But later, when we write the test for the :encrypted_password attribute, he uses respond_to . Out of curiosity, I tried respond_to in the console, for a User object, and I get an error saying the method doesnt exist. Alas, if I try to write the test using respond_to? instead of respond_to , the test doesnt run. Could someone explain me the difference, and why does the test only run

undefined method `save' making test fail before testing to the end

谁说胖子不能爱 提交于 2019-12-02 15:46:24
问题 I am following ruby.railstutorial.org. I have had some troubles, but I solved them. Now, however, I am googling for quite some time, checked the code, I even have an idea why test fails, but have no clue as to how to make it pass. So, here's the problem. I have a User model: class User < ActiveRecord::Base attr_accessible :email, :name validates :name, presence: true, length: {maximum: 50 } VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i validates :email, presence: true, format: {

Rails tutorial: undefined method

纵饮孤独 提交于 2019-12-02 12:07:22
I'm stuck (again!) at Chapter 9 (this time in section 9.2.2) of the Rails tutorial. I am getting bundle exec rspec spec/ ................................FFF........................ Failures: 1) Authentication authorization as wrong user submitting a GET request to the Users#edit action Failure/Error: before {sign_in user, no_capybara: true} NoMethodError: undefined method `new_remember_token' for #<User:0x007f8181815448> # ./spec/support/utilities.rb:13:in `sign_in' # ./spec/requests/authentication_pages_spec.rb:71:in `block (4 levels) in <top (required)>' The other 2 errors are of the same