저는이 문제에 대해 지금 당분간 고민 중이며 어떤 일이 일어나고 있는지 파악할 수 없습니다. 나는 Michael Hartl 's Rails 튜토리얼을 통해 자신의 방식대로 작업하고 있으며 일부 테스트에 문제가있는 것으로 나타났습니다. 그래서 여기 내 user_pages_spec.rb의Hartl 's Rails 튜토리얼 (rails-4-0) 섹션 10.3.2 param을 찾을 수 없습니다.
Failures:
1) User pages signup with invalid information should not create a user
Failure/Error: expect { click_button submit }.not_to change(User, :count)
ActionController::ParameterMissing:
param not found: user
# ./app/controllers/users_controller.rb:61:in `user_params'
# ./app/controllers/users_controller.rb:21:in `create'
# ./spec/requests/user_pages_spec.rb:89:in `block (5 levels) in <top (required)>'
# ./spec/requests/user_pages_spec.rb:89:in `block (4 levels) in <top (required)>'
2) User pages signup with invalid information after submission
Failure/Error: before { click_button submit }
ActionController::ParameterMissing:
param not found: user
# ./app/controllers/users_controller.rb:61:in `user_params'
# ./app/controllers/users_controller.rb:21:in `create'
# ./spec/requests/user_pages_spec.rb:93:in `block (5 levels) in <top (required)>'
3) User pages signup with invalid information after submission
Failure/Error: before { click_button submit }
ActionController::ParameterMissing:
param not found: user
# ./app/controllers/users_controller.rb:61:in `user_params'
# ./app/controllers/users_controller.rb:21:in `create'
# ./spec/requests/user_pages_spec.rb:93:in `block (5 levels) in <top (required)>'
4) User pages signup with valid information should create a user
Failure/Error: before { valid_signup(user) }
Capybara::ElementNotFound:
Unable to find field "Name"
# ./spec/support/utilities.rb:10:in `valid_signup'
# ./spec/requests/user_pages_spec.rb:102:in `block (4 levels) in <top (required)>'
5) User pages signup with valid information after saving the user
Failure/Error: before { valid_signup(user) }
Capybara::ElementNotFound:
Unable to find field "Name"
# ./spec/support/utilities.rb:10:in `valid_signup'
# ./spec/requests/user_pages_spec.rb:102:in `block (4 levels) in <top (required)>'
6) User pages signup with valid information after saving the user
Failure/Error: before { valid_signup(user) }
Capybara::ElementNotFound:
Unable to find field "Name"
# ./spec/support/utilities.rb:10:in `valid_signup'
# ./spec/requests/user_pages_spec.rb:102:in `block (4 levels) in <top (required)>'
7) User pages signup with valid information after saving the user
Failure/Error: before { valid_signup(user) }
Capybara::ElementNotFound:
Unable to find field "Name"
# ./spec/support/utilities.rb:10:in `valid_signup'
# ./spec/requests/user_pages_spec.rb:102:in `block (4 levels) in <top (required)>'
Finished in 9.1 seconds
119 examples, 7 failures
Failed examples:
rspec ./spec/requests/user_pages_spec.rb:88 # User pages signup with invalid information should not create a user
rspec ./spec/requests/user_pages_spec.rb:95 # User pages signup with invalid information after submission
rspec ./spec/requests/user_pages_spec.rb:96 # User pages signup with invalid information after submission
rspec ./spec/requests/user_pages_spec.rb:104 # User pages signup with valid information should create a user
rspec ./spec/requests/user_pages_spec.rb:113 # User pages signup with valid information after saving the user
rspec ./spec/requests/user_pages_spec.rb:115 # User pages signup with valid information after saving the user
rspec ./spec/requests/user_pages_spec.rb:116 # User pages signup with valid information after saving the user
: :이 실패한 테스트 결과입니다
require 'spec_helper'
describe "User pages" do
subject { page }
describe "index" do
let(:user) { FactoryGirl.create(:user) }
before do
sign_in user
visit users_path
end
it { should have_title('All users') }
it { should have_content('All users') }
describe "pagination" do
before(:all) { 30.times { FactoryGirl.create(:user) } }
after(:all) { User.delete_all }
it { should have_selector('div.pagination') }
it "should list each user" do
#User.all.each do |user|
User.paginate(page: 1).each do |user|
expect(page).to have_selector('li', text: user.name)
end
end
end
describe "delete links" do
it { should_not have_link('delete') }
describe "as an admin user" do
let(:admin) { FactoryGirl.create(:admin) }
before do
sign_in admin
visit users_path
end
it { should have_link('delete', href: user_path(User.first)) }
it "should be able to delete another user" do
expect do
click_link('delete', match: :first)
end.to change(User, :count).by(-1)
end
it { should_not have_link('delete', href: user_path(admin)) }
end
end
end
describe "profile page" do
let(:user) { FactoryGirl.create(:user) }
let!(:m1) { FactoryGirl.create(:micropost, user: user, content: "Foo") }
let!(:m2) { FactoryGirl.create(:micropost, user: user, content: "Bar") }
before { visit user_path(user) }
it { should have_content(user.name) }
it { should have_title(user.name) }
describe "microposts" do
it { should have_content(m1.content) }
it { should have_content(m2.content) }
it { should have_content(user.microposts.count) }
end
end
describe "signup page" do
before { visit signup_path }
it { should have_content('Sign up') }
it { should have_title(full_title('Sign up')) }
end
describe "signup" do
before { visit signup_path }
let(:submit) { "Create my account" }
describe "with invalid information" do
it "should not create a user" do
expect { click_button submit }.not_to change(User, :count)
end
describe "after submission" do
before { click_button submit }
it { should have_title('Sign up') }
it { should have_content('error') }
end
end
describe "with valid information" do
let(:user) {FactoryGirl.build(:user)}
before { valid_signup(user) }
it "should create a user" do
expect { click_button submit }.to change(User, :count).by(1)
end
describe "after saving the user" do
before { click_button submit }
#let(:user) { User.find_by(email: '[email protected]') }
it { should have_title(user.name) }
#it { should have_selector('title', text: user.name) }
it { should have_selector('div.alert.alert-success', text: 'Welcome') }
it { should have_link('Sign out') }
end
end
end
describe "edit" do
let(:user) { FactoryGirl.create(:user) }
before do
sign_in user
visit edit_user_path(user)
end
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
describe "with invalid information" do
before { click_button "Save changes" }
it { should have_content('error') }
end
describe "with valid information" do
let(:new_name) { "New Name" }
let(:new_email) { "[email protected]" }
before do
fill_in "Name", with: new_name
fill_in "Email", with: new_email
fill_in "Password", with: user.password
fill_in "Confirm Password", with: user.password
click_button "Save changes"
end
it { should have_title(new_name) }
it { should have_selector('div.alert.alert-success') }
it { should have_link('Sign out', href: signout_path) }
specify { expect(user.reload.name).to eq new_name }
specify { expect(user.reload.email).to eq new_email }
end
describe "forbidden attributes" do
let(:params) do
{ user: {admin: true, password: user.password, password_confirmation: user.password } }
end
before do
sign_in user, no_capybara: true
patch user_path(user), params
end
specify { expect(user.reload).not_to be_admin }
end
end
end
users_controller.rb :
class UsersController < ApplicationController
before_action :signed_in_user, only: [:index, :edit, :update, :destroy]
before_action :correct_user, only: [:edit, :update]
before_action :admin_user, only: :destroy
before_filter :signed_in_user_filter, only: [:new, :create]
def index
@users = User.paginate(page: params[:page])
end
def show
@user = User.find(params[:id])
@microposts = @user.microposts.paginate(page: params[:page])
end
def new
@user = User.new
end
def create
@user = User.new(user_params)
if @user.save
sign_in @user
flash[:success] = "Welcome to the Sample App!"
redirect_to @user
else
render 'new'
end
end
def destroy
@user = User.find(params[:id])
if current_user == @user
flash[:error] = "You must not delete yourself."
#redirect_to users_path
else
@user.destroy
flash[:success] = "User deleted."
#redirect_to users_url
end
redirect_to users_path
end
def edit
#@user = User.find(params[:id])
end
def update
#@user = User.find(params[:id])
if @user.update_attributes(user_params)
flash[:success] = "Profile updated"
redirect_to @user
else
render 'edit'
end
end
private
def user_params
params.require(:user).permit(:name, :email, :password, :password_confirmation)
end
#Before filters
def signed_in_user
unless signed_in?
store_location
redirect_to signin_url, notice: "Please sign in."
end
end
def signed_in_user_filter
redirect_to root_path, notice: "Already logged in" if signed_in?
end
def correct_user
@user = User.find(params[:id])
redirect_to(root_url) unless current_user?(@user)
end
def admin_user
redirect_to(root_url) unless current_user.admin?
end
end
내가 releveant 것 밖에 모르겠어요하지만, 여기에 app/views/users/new.html.erb :
<% provide(:title, 'Sign up') %>
<h1>Sign up</h1>
<div class="row">
<div class="span6 offset3">
<%= form_for(@user) do |f| %>
<%= render 'shared/error_messages', object: f.object %>
<%= f.submit "Create my account", class: "btn btn-large btn-primary" %>
<% end %>
</div>
</div>
솔직히이 문제를 어디에서 찾을 지 100 % 확신하지 못합니다. 이 장에서 내가 한 가장 최근의 변화들과 함께 일어났습니다. 나는 모든 연습을하려고하는데 때로는 내가 편집해야 할 것들이 유사하기 때문에 나는 뭔가를 엉망으로 만들었는지 아니면 그냥 바보 같은 짓을했는지 모른다. 브라우저에서 응용 프로그램을 방문하고 "Sign up"링크를 클릭하여 새 사용자를 등록하면 ActionController :: ParameterMissing in UsersController # create라는 빨간색 레일 오류 페이지가 나타나지만 정확히 무엇을 의미하는지 모르겠습니다. . 나는 실제로 그 코드에 영향을 줄 수있는 코드를 변경했다고 생각하지는 않았지만 이전 연습을 완료하려고 시도 할 때 약간의 문제가 발생했습니다.
도움 주셔서 감사합니다. 이것은 나의 첫 번째 게시물이므로 에티켓/포맷팅에서 큰 실수를하지 않았기를 바랍니다. 평소처럼 비슷한 문제가있는 사람을 찾았지만 아무 것도 찾을 수 없었습니다.
편집 : 새 튜토리얼이 나왔을 때 완료되지 않았으므로이 튜토리얼의 이전 버전에서 작업하고 있다고 덧붙였습니다. 당신은 여기에서 그것을 발견 할 수있다 : http://rails-4-0.railstutorial.org/book/user_microposts
우후! 당신 말이 맞아요. 내 필드는 부분으로 리팩토링되었고, 나는 무슨 일이 일어난 것 같아요. 렌더링 코드를 변경하고 필드를 렌더링하는 선을 삭제하거나 바꿀 때 제가 멀리 떨어진 것 같습니다. 그래서 업데이트되어야 할 것은 _fields.html.erb 부분에서'% render 'shared/error_messages'%>'였고 new.html.erb 나 edit.html.erb에서 일어난 일을 변경하지 않았습니다. 정말 고마워! – gffryclrk