railstutorial.org

SessionsHelper in railstutorial.org: Should helpers be general-purpose modules for code not needed in views?

淺唱寂寞╮ 提交于 2019-11-27 13:44:18
问题 railstutorial.org has a suggestion which strikes me as a little odd. It suggests this code: class ApplicationController < ActionController::Base protect_from_forgery include SessionsHelper end The include SessionsHelper makes the methods available from ApplicationController , yes, but it makes them available in any view, as well. I understand that authentication/authorization is cross-cutting, but is this really the best place? That seems to me to be potentially too broad of a scope. Putting

rake db:migrate is not working

孤街醉人 提交于 2019-11-27 13:43:15
问题 I'm working through the rails tutorial and have gotten stuck. Starting at Listing 8.16 I have made the following modifications to <timestamp>_add_remember_token_to_users.rb : class AddRememberTokenToUsers < ActiveRecord::Migration def change add_column :users, :remember_token, :string add_index :users, :remember_token end end The guide then says to update dev & test db as usual: $ bundle exec rake db:migrate $ bundle exec rake db:test:prepare My User test for the *remember_token* is still

Why does my rails rollback when I try to user.save?

ⅰ亾dé卋堺 提交于 2019-11-27 09:40:31
问题 I have installed the RailsTutorial sample app(the twitter like application) and am trying to understand why the following piece of console code does not update the database when I try updating the user db. I am expecting the user information to get updated once I use the user.save . However, this rolls back to unedited data. Is this due to a user based restriction? Users controller: class UsersController < ApplicationController #before_filter :signed_in_user, only: [:index, :edit, :update,

Micropost character countdown (Rails Tutorial, 2nd Ed, Chapter 10, Exercise 7)

僤鯓⒐⒋嵵緔 提交于 2019-11-27 07:24:04
问题 I attempted the micropost character countdown in The Rails Tutorial (Chapter 10, Exercise 7) using the information here as a base and with some help from StackOverflow answers here and here. On screen, it looks like this, and as you get closer to the character limit, the text gradually turns redder, and once the micropost is overlimit, the Post button disables, finishing like so. The current implementation looks like: views/shared/_micropost_form.html.haml = form_for @micropost do |f| =

Rspec and named routes

╄→尐↘猪︶ㄣ 提交于 2019-11-27 04:22:44
I'm quite new to rails, and trying to follow the railstutorial. Everything goes fine, except for my tests which can't get past the named routes (5.3.3) My routes.rb : SampleApp::Application.routes.draw do resources :users match '/signup', to: 'users#new' match '/help', to: 'static_pages#help' match '/about', to: 'static_pages#about' match '/contact', to: 'pages#contact' root to: 'static_pages#home' #Commented stuff My firsts tests (spec/controllers/static_pages_controller_spec.rb) : describe "Static pages" do subject { page } shared_examples_for "all static pages" do it { should have_selector(

cannot load railtie after upgrade to rails 4 per ruby.railstutorial.org

我只是一个虾纸丫 提交于 2019-11-27 03:01:32
问题 OS is Ubuntu 12.04, 64 bit. New to rails. Relatively new to Ruby. Following the ruby.railstutorial.org tutorial, chapter 3. The tutorial has been updated to use ruby 2.0.0 and Rails 4.0.0.rc1. Previously the gemfile was specifying Rails 3.2.13 and not specifying Ruby version. After moving to the latest Gemfile in the tutorial, ruby 2.0.0 and Rails 4.0.0.rc1, I'm getting the following error when running rails commands. Example here is rails server user@machine:~/bin/railslearn/sample_app$

How do I start enterpiseDB PostgreSQL on Mac OSX 10.6.8?

柔情痞子 提交于 2019-11-27 02:28:43
问题 Mac OSX 10.6.8 The postgres website says postgres 9.2+ is compatible with Mac OSX 10.6+, so I downloaded the 9.2.4 version of the installer for Mac OSX here: http://www.enterprisedb.com/products-services-training/pgdownload I accepted all the defaults, so postgres was installed in the directory: /Library/PostgreSQL/9.2 (If you are installing postgres for rails development, in order to install the pg gem you need to add to your PATH: http://excid3.com/blog/installing-postgresql-and-pg-gem-on

Rails 3 Tutorial Chapter 11 “Validation failed: Email has already been taken” error

一个人想着一个人 提交于 2019-11-27 01:57:51
问题 My trouble arose in Chapter 11 of the Ruby on Rails Tutorial here. I was seeing this rspec error: Failure/Error: :user => Factory(:user, :email => Factory.next(:email))) ActiveRecord::RecordInvalid: Validation failed: Email has already been taken first in user_spec.rb then in micropost_spec.rb . It was pretty puzzling. I thought the factory statements were generating a user in a fresh testing db each time autotest ran rspec. I checked out source files from the master branch with git and tried

Error launching Rails server: undefined method 'configure'

你。 提交于 2019-11-26 21:59:29
I'm new to rails and working through Hartl's tutorial . Everything was fine until I tried to do the tutorial a second time and created another project trying to use the latest version of rails. When I try to load the rails server from the app folder I get the following error. $ rails s => Booting WEBrick => Rails 4.0.4 application starting in development on => Run `rails server -h` for more startup options => Ctrl-C to shutdown server Exiting /Users/sierra/Desktop/sample_app_2/config/environments/development.rb:1:in `<top (required)>': undefined method `configure' for #<SampleApp2::Application

Rspec and named routes

对着背影说爱祢 提交于 2019-11-26 11:09:04
问题 I\'m quite new to rails, and trying to follow the railstutorial. Everything goes fine, except for my tests which can\'t get past the named routes (5.3.3) My routes.rb : SampleApp::Application.routes.draw do resources :users match \'/signup\', to: \'users#new\' match \'/help\', to: \'static_pages#help\' match \'/about\', to: \'static_pages#about\' match \'/contact\', to: \'pages#contact\' root to: \'static_pages#home\' #Commented stuff My firsts tests (spec/controllers/static_pages_controller