“param丢失或值为空:user”

时间:2017-03-09 19:32:00

标签: ruby devise ruby-on-rails-5 nested-forms

我尝试创建Book并创建User。因此,class User < ApplicationRecord devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable has_many :books has_many :covers, through: :books has_many :commands accepts_nested_attributes_for :books end 形式嵌套在class Book < ApplicationRecord has_one :cover belongs_to :user, dependent: :destroy end 中。 但我无法通过,因为我有这个错误:

  
    

param丢失或值为空

  

我看了一下人们得到这个错误的松弛问题。

但是没有人适合我的情况。

所以,如果您有任何想法,请随时提供帮助。

user.rb

class RegistrationsController < Devise::RegistrationsController
  def new
    build_resource(sign_up_params)
    self.resource.books = Book.new
    respond_with self.resource
  end

  def create
    super
  end

  private

  def sign_up_params
    params.require(resource_name).permit(:email, :password, :password_confirmation, :books_attributes[:title, :author_first_name, :author_last_name])
  end
end

book.rb

resource_name

registrations_controller

:user

我检查了h2 | Sign up = form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| = devise_error_messages! .field = f.label :email br = f.email_field :email, autofocus: true .field = f.label :password - if @minimum_password_length em | ( = @minimum_password_length | characters minimum) br = f.password_field :password, autocomplete: "off" .field = f.label :password_confirmation br = f.password_field :password_confirmation, autocomplete: "off" = f.fields_for :books do |p| = p.text_field :title = p.text_field :author_first_name = p.text_field :author_last_name .actions = f.submit "Sign up" = render "devise/shared/links" ,它恰好等于Rails.application.routes.draw do devise_for :users, controllers: {registrations: 'registrations'} root 'home#index' end

设计/注册/新

Started GET "/users/sign_up" for ::1 at 2017-03-10 08:59:00 +0100
Processing by RegistrationsController#new as HTML
Completed 400 Bad Request in 1ms (ActiveRecord: 0.0ms)



ActionController::ParameterMissing - param is missing or the value is empty: user:
  actionpack (5.0.2) lib/action_controller/metal/strong_parameters.rb:309:in `require'
  app/controllers/registrations_controller.rb:15:in `sign_up_params'
  app/controllers/registrations_controller.rb:3:in `new'
  actionpack (5.0.2) lib/action_controller/metal/basic_implicit_render.rb:4:in `send_action'
  actionpack (5.0.2) lib/abstract_controller/base.rb:188:in `process_action'
  actionpack (5.0.2) lib/action_controller/metal/rendering.rb:30:in `process_action'
  actionpack (5.0.2) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
  activesupport (5.0.2) lib/active_support/callbacks.rb:126:in `call'
  activesupport (5.0.2) lib/active_support/callbacks.rb:506:in `block (2 levels) in compile'
  activesupport (5.0.2) lib/active_support/callbacks.rb:455:in `call'
  activesupport (5.0.2) lib/active_support/callbacks.rb:101:in `__run_callbacks__'
  activesupport (5.0.2) lib/active_support/callbacks.rb:750:in `_run_process_action_callbacks'
  activesupport (5.0.2) lib/active_support/callbacks.rb:90:in `run_callbacks'
  actionpack (5.0.2) lib/abstract_controller/callbacks.rb:19:in `process_action'
  actionpack (5.0.2) lib/action_controller/metal/rescue.rb:20:in `process_action'
  actionpack (5.0.2) lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
  activesupport (5.0.2) lib/active_support/notifications.rb:164:in `block in instrument'
  activesupport (5.0.2) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
  activesupport (5.0.2) lib/active_support/notifications.rb:164:in `instrument'
  actionpack (5.0.2) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
  actionpack (5.0.2) lib/action_controller/metal/params_wrapper.rb:248:in `process_action'
  activerecord (5.0.2) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
  actionpack (5.0.2) lib/abstract_controller/base.rb:126:in `process'
  actionview (5.0.2) lib/action_view/rendering.rb:30:in `process'
  actionpack (5.0.2) lib/action_controller/metal.rb:190:in `dispatch'
  actionpack (5.0.2) lib/action_controller/metal.rb:262:in `dispatch'
  actionpack (5.0.2) lib/action_dispatch/routing/route_set.rb:50:in `dispatch'
  actionpack (5.0.2) lib/action_dispatch/routing/route_set.rb:32:in `serve'
  actionpack (5.0.2) lib/action_dispatch/routing/mapper.rb:16:in `block in <class:Constraints>'
  actionpack (5.0.2) lib/action_dispatch/routing/mapper.rb:46:in `serve'
  actionpack (5.0.2) lib/action_dispatch/journey/router.rb:39:in `block in serve'
  actionpack (5.0.2) lib/action_dispatch/journey/router.rb:26:in `serve'
  actionpack (5.0.2) lib/action_dispatch/routing/route_set.rb:725:in `call'
  warden (1.2.7) lib/warden/manager.rb:36:in `block in call'
  warden (1.2.7) lib/warden/manager.rb:35:in `call'
  rack (2.0.1) lib/rack/etag.rb:25:in `call'
  rack (2.0.1) lib/rack/conditional_get.rb:25:in `call'
  rack (2.0.1) lib/rack/head.rb:12:in `call'
  rack (2.0.1) lib/rack/session/abstract/id.rb:222:in `context'
  rack (2.0.1) lib/rack/session/abstract/id.rb:216:in `call'
  actionpack (5.0.2) lib/action_dispatch/middleware/cookies.rb:613:in `call'
  activerecord (5.0.2) lib/active_record/migration.rb:553:in `call'
  actionpack (5.0.2) lib/action_dispatch/middleware/callbacks.rb:38:in `block in call'
  activesupport (5.0.2) lib/active_support/callbacks.rb:97:in `__run_callbacks__'
  activesupport (5.0.2) lib/active_support/callbacks.rb:750:in `_run_call_callbacks'
  activesupport (5.0.2) lib/active_support/callbacks.rb:90:in `run_callbacks'
  actionpack (5.0.2) lib/action_dispatch/middleware/callbacks.rb:36:in `call'
  actionpack (5.0.2) lib/action_dispatch/middleware/executor.rb:12:in `call'
  actionpack (5.0.2) lib/action_dispatch/middleware/remote_ip.rb:79:in `call'
  better_errors (2.1.1) lib/better_errors/middleware.rb:84:in `protected_app_call'
  better_errors (2.1.1) lib/better_errors/middleware.rb:79:in `better_errors_call'
  better_errors (2.1.1) lib/better_errors/middleware.rb:57:in `call'
  actionpack (5.0.2) lib/action_dispatch/middleware/debug_exceptions.rb:49:in `call'
  web-console (3.4.0) lib/web_console/middleware.rb:135:in `call_app'
  web-console (3.4.0) lib/web_console/middleware.rb:28:in `block in call'
  web-console (3.4.0) lib/web_console/middleware.rb:18:in `call'
  actionpack (5.0.2) lib/action_dispatch/middleware/show_exceptions.rb:31:in `call'
  railties (5.0.2) lib/rails/rack/logger.rb:36:in `call_app'
  railties (5.0.2) lib/rails/rack/logger.rb:24:in `block in call'
  activesupport (5.0.2) lib/active_support/tagged_logging.rb:69:in `block in tagged'
  activesupport (5.0.2) lib/active_support/tagged_logging.rb:26:in `tagged'
  activesupport (5.0.2) lib/active_support/tagged_logging.rb:69:in `tagged'
  railties (5.0.2) lib/rails/rack/logger.rb:24:in `call'
  sprockets-rails (3.2.0) lib/sprockets/rails/quiet_assets.rb:13:in `call'
  actionpack (5.0.2) lib/action_dispatch/middleware/request_id.rb:24:in `call'
  rack (2.0.1) lib/rack/method_override.rb:22:in `call'
  rack (2.0.1) lib/rack/runtime.rb:22:in `call'
  activesupport (5.0.2) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
  actionpack (5.0.2) lib/action_dispatch/middleware/executor.rb:12:in `call'
  actionpack (5.0.2) lib/action_dispatch/middleware/static.rb:136:in `call'
  rack (2.0.1) lib/rack/sendfile.rb:111:in `call'
  railties (5.0.2) lib/rails/engine.rb:522:in `call'
  puma (3.7.1) lib/puma/configuration.rb:232:in `call'
  puma (3.7.1) lib/puma/server.rb:578:in `handle_request'
  puma (3.7.1) lib/puma/server.rb:415:in `process_client'
  puma (3.7.1) lib/puma/server.rb:275:in `block in run'
  puma (3.7.1) lib/puma/thread_pool.rb:120:in `block in spawn_thread'

Started POST "/__better_errors/8c394ae550fda307/variables" for ::1 at 2017-03-10 08:59:00 +0100

修改

路由

structure(list(xdata = c(-5, -5.30102999566398, -5.60205999132796, 
-5.90308998699194, -6.20411998265593, -6.50514997831991), A = c(97.15, 
98.44, 96.47, 73.69, 60.97, 45.13), B = c(116.11, 124.08, 110.08, 
111.81, 118.25, 78.09), C = c(108.4, 127.6, 96.47, 124.87, 136.49, 
104.69), D = c(107.27, 118.25, 99.05, 99.49, 104.02, 99.58), 
    necafT = c(109.45, 104.98, 101.66, 101.2, 108.4, 101.57)), .Names = c("xdata", 
"A", "B", "C", "D", "necafT"), row.names = c(NA, 6L), class = "data.frame")

ec50_1 = as.numeric(Globals$EC50[1]) ;    conc1 = as.numeric(Globals$conc1[1])
antag1 = 1+(conc1/(10**(-1*Globals$pa2[1])))**1 ;  logEC1 = log10(ec50_1*antag1)
TOP1 = as.numeric(Globals$Top[1]);  BOTTOM1 = as.numeric(Globals$Bottom[1]);  hillSlope = 1
fit1 <- nls(A ~ BOTTOM + (TOP-BOTTOM)/(1+10**((logEC-xdata)*hillSlope)), data= COMPD1,
           start=list(TOP = TOP1, BOTTOM = BOTTOM1, hillSlope = 1, logEC = logEC1))
pred1 <- fitted(fit1)
fit2 <- nls(B ~ BOTTOM + (TOP-BOTTOM)/(1+10**((logEC-xdata)*hillSlope)), data= COMPD1,
            start=list(TOP = TOP1, BOTTOM = BOTTOM1, hillSlope = 1, logEC = logEC1))
pred2 <- fitted(fit2)
fit3 <- nls(C ~ BOTTOM + (TOP-BOTTOM)/(1+10**((logEC-xdata)*hillSlope)), data= COMPD1,
            start=list(TOP = TOP1, BOTTOM = BOTTOM1, hillSlope = 1, logEC = logEC1))
pred3 <- fitted(fit3)
fit4 <- nls(D ~ BOTTOM + (TOP-BOTTOM)/(1+10**((logEC-xdata)*hillSlope)), data= COMPD1,
            start=list(TOP = TOP1, BOTTOM = BOTTOM1, hillSlope = 1, logEC = logEC1))
pred4 <- fitted(fit4)
fit5 <- nls(necafT ~ BOTTOM + (TOP-BOTTOM)/(1+10**((logEC-xdata)*hillSlope)), data= COMPD1,
            start=list(TOP = TOP1, BOTTOM = BOTTOM1, hillSlope = 1, logEC = logEC1))
pred5 <- fitted(fit5)

ggplot(COMPD1, aes(y = A,x = xdata, fill = "A",colour="A"))+geom_point(shape = 21, size = 4,colour="black")+ 
geom_line(aes(y = pred1,x =  xdata),size = 1.5,colour="blue1")+
  geom_point(aes(y = B,x =  xdata, fill = "B",colour="black"),shape = 22,size = 4,colour="black")+
  geom_line(aes(y = pred2,x =  xdata),size = 1.5,colour="red")+
  geom_point(aes(y = C,x =  xdata, fill = "C"),shape = 23,size = 4,colour="black")+
  geom_line(aes(y = pred3,x =  xdata),size = 1.5,colour="green")+
  geom_point(aes(y = D,x =  xdata, fill = "D"),shape = 24, size = 4,colour="black")+
  geom_line(aes(y = pred4,x =  xdata),size = 1.5,colour="black")+
  geom_point(aes(y = necafT,x =  xdata, fill = "necafT"),shape = 25,size = 4,colour="black")+
  geom_line(aes(y = pred5,x =  xdata),size = 1.5,colour="orchid")+
  xlab('Log Concn')+ ylab('LogEC50')+ggtitle("Global Fit")+ theme_classic()+
  theme(legend.title = element_text(colour="blue", size=10, face="bold"),
    legend.position="bottom",panel.background = element_rect(colour = "black", size=1),
    plot.margin = margin(1, 2, 1, 1, "cm"),
    plot.title = element_text(hjust = 0),
    axis.title = element_text(face="bold", color="#966666", size=14),
    axis.text.x = element_text(face="bold", color="#666666", size=12),
    axis.text.y = element_text(face="bold", color="#666666", size=12))

登录

Scanner kb = new Scanner(System.in);
System.out.print("Enter the number of your triangle (1 to 50): ");
int input = kb.nextInt();
for (int i = 0; i < input; i++) {
  System.out.println();
  for (int j = 0; j <= i; j++) {
    System.out.print("*");
  }
}
for (int i = input - 1; i > 0; i--) {
  System.out.println();
  for (int j = 0; j < i; j++) {
    System.out.print("*");
  }
}

1 个答案:

答案 0 :(得分:0)

我终于明白了这个错误的来源。

当你拨打params时,你只需要在create行动中给他们打电话。在new操作中调用它们将产生错误。

编辑后的代码:

class RegistrationsController < Devise::RegistrationsController
  def new
    build_resource
    self.resource.books = Book.new
    respond_with self.resource
  end

  ......

 end