简体   繁体   English

设计添加用户送货地址

[英]Devise adding User shipping address

I'm creating a marketplace. 我正在创造一个市场。 I have user accounts handled by devise. 我有设计处理的用户帐户。 I'd like to add extra user attributes. 我想添加额外的用户属性。 Such as billing and shipping address (and a primary address that takes care of both for most cases). 例如计费和送货地址(以及在大多数情况下都要处理这两种情况的主要地址)。

Devise is configured using default settings. 使用默认设置配置Devise。 I have used this tool to generate devise controllers in my app controllers folder under the users folder. 我使用此工具在users文件夹下的app控制器文件夹中生成设计控制器。 As I found quite a few posts with people trying to render a form from a different controller/view. 因为我发现了很多人试图从不同的控制器/视图渲染表单。

I generated user_address 我生成了user_address

class CreateUserAddresses < ActiveRecord::Migration
  def change
  create_table :user_addresses do |t|
    t.string :address
    t.string :city
    t.string :state
    t.integer :user_id

    t.timestamps null: false
  end
 end
end

And also added a primary address id to my users profile to be used later. 并且还在我的用户配置文件中添加了主要地址ID,以便稍后使用。

class AddPrimraryAddressIdToUsers < ActiveRecord::Migration
  def change
    add_column :users, :primary_address_id, :integer
  end
end

Now I basically want to integrate this user_address _form.html.erb into my devise user. 现在我基本上想要将此user_address _form.html.erb集成到我的设计用户中。

./app/views/user_addresses/_form.html.erb ./app/views/user_addresses/_form.html.erb

./app/views/devise/registrations/edit.html.erb ./app/views/devise/registrations/edit.html.erb

<div>
<% if current_user.primary_address_id.blank? %>
   Please create a primary address
      <%= render :partial => '/user_addresses/form'%>
<% end %>
</div>

Which creates and error on the edit page. 在编辑页面上创建和错误。

First argument in form cannot contain nil or be empty

<%= form_for(@user_address) do |f| %>
  <% if @user_address.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@user_address.errors.count, "error") %> prohibited this user_address from being saved:</h2>

  <ul>

Which my understanding is because user_address is not in the devise user controller. 我的理解是因为user_address不在设计用户控制器中。 How would I integrate everything that user_address created into the devise views and controller to clean up the directory. 如何将user_address创建的所有内容集成到设计视图和控制器中以清理目录。 Or simply render the user_address form. 或者只是渲染user_address表单。

Thanks nic 谢谢你

Is there more functionality in Useraddresses going forward? Useraddresses中有更多功能吗? Or is the sole functionality to add attributes to the User Class. 或者是向User Class添加属性的唯一功能。 If so, then checkout the post here 如果是这样,那么请在这里查看帖子

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM