Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 带有设计注册表的嵌套字段_Ruby On Rails_Ruby_Ruby On Rails 4 - Fatal编程技术网

Ruby on rails 带有设计注册表的嵌套字段

Ruby on rails 带有设计注册表的嵌套字段,ruby-on-rails,ruby,ruby-on-rails-4,Ruby On Rails,Ruby,Ruby On Rails 4,我正在尝试在设计注册/注册中添加一些嵌套字段。我有一个商店模型(它是用户模型)和一个帐户模型。我已经为store和account创建了控制器(使用rails生成designe:controllers)和视图(使用rails生成designe:views)。我试图在商店注册/注册中传递帐户模型中的一些嵌套字段,以便注册用户并创建帐户。商店确实注册了,但没有创建帐户 以下是我想做的: routes.rb Rails.application.routes.draw do devise_for :sto

我正在尝试在设计注册/注册中添加一些嵌套字段。我有一个商店模型(它是用户模型)和一个帐户模型。我已经为store和account创建了控制器(使用rails生成designe:controllers)和视图(使用rails生成designe:views)。我试图在商店注册/注册中传递帐户模型中的一些嵌套字段,以便注册用户并创建帐户。商店确实注册了,但没有创建帐户

以下是我想做的:

routes.rb

Rails.application.routes.draw do
devise_for :stores, :controllers => { registrations: "stores/registrations",
                                    sessions: "stores/sessions" }

devise_scope :store do
get "stores/index"=> "stores/sessions#index", :as => "store_index"
get "stores/sign_up"=> "stores/registrations#new", :as => "store_sign_up"
get "stores/sign_in"=> "stores/sesssions#new", :as => "store_sign_in"
get "stores/sing_out"=> "stores/sesssions#destroy", :as => "store_sing_out"
end
store.rb

class Store < ApplicationRecord
  devise :database_authenticatable, :registerable,
     :recoverable, :rememberable, :trackable, :validatable

  has_one :account, :autosave => true

  accepts_nested_attributes_for :account
end

罪魁祸首是的
字段。您应该
表单\u为
实例(在您的例子中是
f
)包装它。所以
应该是

class Account < ApplicationRecord
  belongs_to :store
end
class Stores::RegistrationsController < Devise::RegistrationsController
  before_action :configure_permitted_parameters, if: :devise_controller?
  skip_before_action :verify_authenticity_token, :only => :create

   def new
     build_resource({})
     resource.build_account
     respond_with self.resource
    end


   def create
     super
   end


   def edit
     super
    end


   def update
     super
   end


   def destroy
     super
   end

   def cancel
     super
   end

  protected

  def configure_permitted_parameters
    devise_parameter_sanitizer.permit(:sign_up) { |u|
      u.permit(:email, :password, :password_confirmation, :remember_me,
           :account_attributes => [:first_name, :last_name, :buisness_name,
                                   :buisness_description, :web_site, :phone_number,
                                   :street, :city, :zip_code, :country])
}
  end


  # The path used after sign up.
  def after_sign_up_path_for(resource)
    items_path(resource)
   end

  end
<h2>Sign up</h2>

<% resource.build_account if resource.account.nil? %>
<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
  <%= devise_error_messages! %>

  <div class="field">
    <%= f.label :email %><br />
    <%= f.email_field :email, autofocus: true %>
  </div>

  <div class="field">
   <%= f.label :password %>
   <% if @minimum_password_length %>
   <em>(<%= @minimum_password_length %> characters minimum)</em>
   <% end %><br />
   <%= f.password_field :password, autocomplete: "off" %>
   </div>

   <div class="field">
    <%= f.label :password_confirmation %><br />
    <%= f.password_field :password_confirmation, autocomplete: "off" %>
   </div>


<%= fields_for :account do |form| %>
  <div class="field">
    <%= form.label :first_name %>
    <%= form.text_field :first_name, id: :account_first_name %>
  </div>

  <div class="field">
    <%= form.label :last_name %>
    <%= form.text_field :last_name, id: :account_last_name %>
  </div>

  <div class="field">
    <%= form.label :buisness_name %>
    <%= form.text_field :buisness_name, id: :account_buisness_name %>
  </div>

   <div class="field">
    <%= form.label :buisness_description %>
    <%= form.text_field :buisness_description, id: :account_buisness_description %>
   </div>

  <div class="field">
    <%= form.label :web_site %>
    <%= form.text_field :web_site, id: :account_web_site %>
  </div>

  <div class="field">
    <%= form.label :phone_number %>
    <%= form.text_field :phone_number, id: :account_phone_number %>
  </div>

  <div class="field">
   <%= form.label :street %>
   <%= form.text_field :street, id: :account_street %>
  </div>

  <div class="field">
    <%= form.label :city %>
    <%= form.text_field :city, id: :account_city %>
  </div>

  <div class="field">
    <%= form.label :state %>
    <%= form.text_field :state, id: :account_state %>
  </div>

  <div class="field">
   <%= form.label :zip_code %>
   <%= form.text_field :zip_code, id: :account_zip_code %>
  </div>

  <div class="field">
   <%= form.label :country %>
   <%= form.text_field :country, id: :account_country %>
  </div>
  <% end %>

  <div class="actions">
    <%= f.submit "Sign up" %>
  </div>
<% end %>

<%= render "stores/shared/links" %>
Started POST "/stores" for 127.0.0.1 at 2017-07-02 11:34:25 +0300
Processing by Stores::RegistrationsController#create as HTML
Parameters: {"utf8"=>"✓",  "authenticity_token"=>"ltsFRnWTbbghe/Hve+gqpJ5SVmpqB8bzgNo9PnEUc2DYE0hQLWRb 2JgAoUtSex2QlmynColjljxWOHQYxhWzLA==", "store"=> {"email"=>"test9@gmail.com", "password"=>"[FILTERED]",  "password_confirmation"=>"[FILTERED]"}, "account"=>{"first_name"=>"1", "last_name"=>"1", "buisness_name"=>"1", "buisness_description"=>"1", "web_site"=>"1", "phone_number"=>"1", "street"=>"1", "city"=>"1", "state"=>"1", "zip_code"=>"1", "country"=>"1"}, "commit"=>"Sign up"}
   (0.1ms)  begin transaction
  Store Exists (0.2ms)  SELECT  1 AS one FROM "stores" WHERE "stores"."email" = ? LIMIT ?  [["email", "test9@gmail.com"], ["LIMIT", 1]]
  SQL (0.5ms)  INSERT INTO "stores" ("email", "encrypted_password", "created_at", "updated_at") VALUES (?, ?, ?, ?)  [["email", "test9@gmail.com"], ["encrypted_password", "$2a$11$K2bdPn80L47p8tFdMrvj5e8J.0SFPB5QgwLu8I6OYDV5j08BrSshy"], ["created_at", "2017-07-02 08:34:25.447647"], ["updated_at", "2017-07-02 08:34:25.447647"]]
   (1.5ms)  commit transaction
   (0.2ms)  begin transaction
  SQL (0.3ms)  UPDATE "stores" SET "sign_in_count" = ?, "current_sign_in_at" = ?, "last_sign_in_at" = ?, "current_sign_in_ip" = ?, "last_sign_in_ip" = ?, "updated_at" = ? WHERE "stores"."id" = ?  [["sign_in_count", 1], ["current_sign_in_at", "2017-07-02 08:34:25.452166"], ["last_sign_in_at", "2017-07-02 08:34:25.452166"], ["current_sign_in_ip", "127.0.0.1"], ["last_sign_in_ip", "127.0.0.1"], ["updated_at", "2017-07-02 08:34:25.453031"], ["id", 9]]
   (0.6ms)  commit transaction
Redirected to http://localhost:3000/items.9
Completed 302 Found in 168ms (ActiveRecord: 3.4ms)