- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
您好,我是个菜鸟,如果您对此有任何帮助,我将不胜感激。我正在尝试使用用户保存在他们地址簿中的数据,之后我想让他们选择使用该地址进行递送。
这是我的地址 Controller
class AddressesController < ApplicationController
before_action :authenticate_user!
before_action :set_address, only: [ :show, :edit, :update, :destroy]
# GET /addresses
# GET /addresses.json
def index
@addresses = current_user.addresses.all
end
# GET /addresses/1
# GET /addresses/1.json
def show
end
# GET /addresses/new
def new
@address = current_user.addresses.build
end
# GET /addresses/1/edit
def edit
end
# POST /addresses
# POST /addresses.json
def create
@address = current_user.addresses.build(address_params)
@address = current_user
respond_to do |format|
if @address.save
format.html { redirect_to addresses_url, notice: 'Address was successfully created.' }
format.json { render :show, status: :created, location: @address }
else
format.html { render :new }
format.json { render json: @address.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /addresses/1
# PATCH/PUT /addresses/1.json
def update
respond_to do |format|
if @address.update(address_params)
format.html { redirect_to @address, notice: 'Address was successfully updated.' }
format.json { render :show, status: :ok, location: @address }
else
format.html { render :edit }
format.json { render json: @address.errors, status: :unprocessable_entity }
end
end
end
# DELETE /addresses/1
# DELETE /addresses/1.json
def destroy
@address.destroy
respond_to do |format|
format.html { redirect_to addresses_url, notice: 'Address was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_address
@address = Address.find(params[:id])
end
# Only allow a list of trusted parameters through.
def address_params
params.require(:address).permit(:address, :latitude, :longitude)
end
end
还有我的地址表,它使用谷歌地图 API 来获取用户的经度和纬度
<%= simple_form_for(@address) do |f| %>
<p class="text-danger" style="width: 500px;">Your address will only be used for deliveries. This is mainly for locating unknown land marks like a household not for use of well known companies or easily locatable land marks. Eg "Little Bay Peer". Mobile users may allow location as it will be more accurate, users on a computer should use the map.</p>
<div class="form-inputs" style="width: 500px">
<%= f.input :address %>
<%= f.input :latitude, id: "address_latitude" %>
<%= f.input :longitude, id: "address_longitude" %>
</div>
<em>Please use the zoom button while redirecting the marker to the exact location you want your delivery </em>
<p>
<div id="map2" ></div>
</p>
<div class="form-actions">
<%= f.button :submit, class: "btn btn-success" %><br><br>
</div>
<% end %>
</div>
这是我不确定的地方这是我的订单 Controller
before_action :authenticate_user!
before_action :set_already_order, only: [:show, :edit, :update, :destroy]
# GET /already_orders
# GET /already_orders.json
def index
@already_orders = current_user.already_orders.order('created_at desc')
end
# GET /already_orders/1
# GET /already_orders/1.json
def show
end
# GET /already_orders/new
def new
@already_order = current_user.already_orders.build
end
# GET /already_orders/1/edit
def edit
end
# POST /already_orders
# POST /already_orders.json
def create
@already_order = current_user.already_orders.build(already_order_params)
@already_order = current_user
respond_to do |format|
if @already_order.save
format.html { redirect_to already_orders_url , notice: 'Already order was successfully created.' }
format.json { render :show, status: :created, location: @already_order }
else
format.html { render :new }
format.json { render json: @already_order.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /already_orders/1
# PATCH/PUT /already_orders/1.json
def update
respond_to do |format|
if @already_order.update(already_order_params)
format.html { redirect_to already_orders_url, notice: 'Already order was successfully updated.' }
format.json { render :show, status: :ok, location: @already_order }
else
format.html { render :edit }
format.json { render json: @already_order.errors, status: :unprocessable_entity }
end
end
end
# DELETE /already_orders/1
# DELETE /already_orders/1.json
def destroy
@already_order.destroy
respond_to do |format|
format.html { redirect_to already_orders_url, notice: 'Already order was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_already_order
@already_order = AlreadyOrder.find(params[:id])
end
# Only allow a list of trusted parameters through.
def already_order_params
params.require(:already_order).permit(:shop_name,
:pick_up_time,
:shop_address,
:shop_district,
:delivery_time,
:item_type,
:item_cost,
:item_quantity,
:name,
:address,
:district,
:building,
:phone_number,
:specific_instructions,
:payment_method,
:cost,
:deliver_id,
:payment_status,
:specify_delivery_time,
:paid_for,
:discount_code,
:delivery_status,
:cost_usd)
end
end
这是我的订单
<%= form_for(@already_order) do |f| %>
<div class="row p-3 pt-5">
<div class="col-md-8 order-md-1">
<h3 class="mb-3 text-muted">Pickup Details</h3>
<div class="form-row">
<div class="form-group form-group col-md-6">
<label>Business name</label>
<%= f.hidden_field :deliver_id, value: SecureRandom.hex(5) %>
<%= f.hidden_field :payment_status, value: "Pending" %>
<%= f.hidden_field :delivery_status %>
<%= f.text_field :shop_name, class:"form-control", placeholder: "Grand Phenix", required: true %>
</div>
<div class="form-group col-md-6">
<label>Business address</label>
<%= f.text_field :shop_address, class:"form-control", placeholder: "Brades", required: true %>
</div>
<div class="form-group col-md-9">
<label>Business district</label><em style="font-size: 12px;"> if business district and delivery district are diffrent you will be charged $4</em>
<%= f.select :shop_district, ['','Cojoehead - Sweenyes', "St. John's - Look Out" , 'Cheapend - Salem'], {}, { :class => 'form-control', :id => 'dist1', :onchange => 'addto()' } %>
</div>
<div class="form-group col-md-3">
<%= f.label :pick_up_time %>
<div class="form-inline">
<%= f.datetime_select :pick_up_time, { ampm: true, order: [:hour, :minute] }, { class:"form-control", :required => true } %>
</div>
</div>
<div class="form-group col-md-5">
<label>Address</label>
<%= f.select("address", Address.all.collect {|p| [ p.address ] },{}, { :class => 'form-control' })%>
</div>
<div class="form-group col-md-5">
<label>Item Type</label>
<%= f.select :item_type, ['','Food & Drinks', "Groceries" , 'Packages'], {}, { :class => 'form-control', :id => 'sitem', :onchange => 'addto()' } %>
</div>
<p id="item_cost"></p>
<p id="dis_cost"></p>
<div class="form-group col-md-4">
<label>Item Quantity or Weight in lbs</label>
<%= f.number_field :item_quantity, class: 'form-control' , id:'weight', :onchange => 'addto()' %>
</div>
<div class="form-group col-md-3">
<%= f.label :delivery_time %>
<div class="form-inline">
<%= f.select :delivery_time, ['8:00 am', '11:50 am', '3:00 pm', '7:30 pm'], {}, { :class => 'form-control' } %>
</div>
</div>
</div><br><br><br>
<h3 class="text-muted">Delivery Details </h3>
<div class="form-row">
<div class="form-group col-md-5">
<%= f.label :name %>
<%= f.text_field :name, class:"form-control", placeholder: "John Browne", required: true %>
</div>
<div class="form-group col-md-5">
</div>
<div class="form-group col-md-6">
<%= f.label :building %>
<%= f.text_field :building, class:"form-control", placeholder: "Third house on the right", required: true %>
</div>
<div class="form-group col-md-10">
<%= f.label :district %><em style="font-size: 12px;"> if delivery district and shop district are diffrent you will be charged $4</em>
<%= f.select :district, ['','Cojoehead - Sweenyes', "St. John's - Look Out" , 'Cheapend - Salem'], {}, { :class => 'form-control', :id => 'dist2', :onchange => 'addto()' } %>
</div>
<div class="form-group col-md-4">
<%= f.label :phone_number %>
<%= f.number_field :phone_number, class:"form-control", placeholder: "393-0000", required: true %>
</div>
<div class="form-group col-md-10">
<%= f.label :specific_instructions %>
<%= f.text_area :specific_instructions, class:"form-control", placeholder: "Knock on the pink door downstairs and deliver it to Tim Browne ", :size => "24x6", :required => true %>
</div>
</div>
<!-- Button trigger modal -->
<div class="ml-3">
<input class="form-check-input" type="checkbox" required>
<button type="button" class="btn btn-info" data-toggle="modal" data-target="#staticBackdrop">
Terms and Conditions
</button>
</div>
<!-- Modal -->
<div class="modal fade" id="staticBackdrop" data-backdrop="static" data-keyboard="false" tabindex="-1" role="dialog" aria-labelledby="staticBackdropLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="staticBackdropLabel">Instructions and Pricing</h5>
</div>
<div class="modal-body">
Please ensure that the Pickup district and delivery district are correct as you will be charged $5 for wrong details.<br><br>
<div class="mx-2"><strong>Food and Drinks</strong> <br>
<em>1 Food and Drink is are a pair as 1</em><br>
1-2 Food and Drinks = $5 <br>
3-6 Food and Drinks = $10 <br>
More and 6 Food and Drinks = $1.6 per <br>
<strong>Groceries</strong> <br>
$1.75 per lb <br>
<strong>Items</strong> <br>
$2.2 per lb </div><br><br>
<h5>Paymant options</h5>
<div class="mx-2"><strong>Already paid</strong> - The item is already paid for and it ready for pick up <br>
<strong>Pay on arrival</strong> - This only applies for items under $50 where Deliver will pay for the item and apon delivery the amount will be paid back plus a $5 fee </div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal">Understood</button>
</div>
</div>
</div>
</div><br><br>
</div>
<div class="col-md-4 order-md-2 mb-4 text-danger">
<h4 class="d-flex justify-content-between align-items-center mb-3">
<span class="text-muted">Charges</span>
</h4>
<ul class="list-group mb-2">
<li class="list-group-item d-flex justify-content-between lh-condensed">
<p id="pitem"></p>
<span class="text-muted" id="price"></span>
</li>
<li class="list-group-item d-flex justify-content-between lh-condensed">
<p id="district"></p>
<span class="text-muted" id="district_cost"></span>
</li>
<li class="list-group-item d-flex justify-content-between lh-condensed">
<p id="payment"></p>
<span class="text-muted" id="pay_cost"></span>
</li>
<li class="list-group-item d-flex justify-content-between lh-condensed">
<p></p>
<span class="text-muted"></span>
</li>
</ul><br>
<span class="text-muted">Payment Method</span><br>
<div>
<%= f.select :payment_method, ['Paypal/Credit Card', "Pay on Arrival"], {}, { :class => 'form-control', :id => 'pay_opt', :onchange => 'addto()' } %>
</div><br><br>
<p id="ttl1"></p>
<p id="ttl2"></p>
<p id="ttl3"></p>
<li class="list-group-item d-flex justify-content-between">
<h5>Total (EC)</h5>
<%= f.hidden_field :cost, id: "ptotal" %>
<%= f.hidden_field :cost_usd, id: "usdtotal" %>
<strong id="end"></strong>
</li>
<br>
<div class="input-group">
<%= f.hidden_field :discount_code, class: 'form-control' %>
<input type="text" class="form-control" placeholder="Discount code">
<div class="input-group-append">
<p class="btn btn-secondary">Redeem</p>
</div>
</div>
</div>
</div>
<div class="form-actions">
<%= f.button :Submit, class: "btn btn-success", id: 'display' %>
</div>
<% end %>
</div>
<p id="pay_val"></p>
<p id="end2"></p>
我用它来显示已保存地址的选项
<%= f.select("address", Address.all.collect {|p| [ p.address ] },{}, { :class => 'form-control' })%>
但是当我提交数据时,我得到一个关联未匹配错误,我也不认为代码正在按我想要的方式工作,因为在提交订单后我希望提交关联的地址名称、经度和纬度与它。
我的模型关联是
class Address < ApplicationRecord
belongs_to :user
has_many :already_orders
has_many :orders
end
class AlreadyOrder < ApplicationRecord
belongs_to :user
has_one :address
end
class User < ApplicationRecord
has_many :already_orders, dependent: :destroy
has_many :orders, dependent: :destroy
has_many :addresses, dependent: :destroy
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :validatable
end
如果能帮助解决这个问题,我将不胜感激
最佳答案
在这里暗中刺一下,但我认为问题是这样的:
<%= f.select("address", Address.all.collect {|p| [ p.address ] },{}, { :class => 'form-control' })%>
选择表单助手的第二个参数接受一个二维数组。
现在你给它的数组翻译成这样:
[['the value of the Address objects address attribute'], ['the value of the Address objects address attribute']]
你希望数组看起来像这样:
[['the value of the Address objects address attribute', address_object_id], ['the value of the Address objects address attribute', address_object_id]]
Rails 将迭代外部数组,并将每个内部数组的索引 0 用于 HTML 选项标记的 innerText。它将使用每个内部数组的索引 1 作为 HTML 选项标签的值。
那行代码的固定版本是这样的:
<%= f.select("address", Address.all.collect {|p| [ p.address, p.id ] },{}, { :class => 'form-control' })%>
关于javascript - Rails 通讯录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62941825/
您好,我是个菜鸟,如果您对此有任何帮助,我将不胜感激。我正在尝试使用用户保存在他们地址簿中的数据,之后我想让他们选择使用该地址进行递送。 这是我的地址 Controller class Address
我目前正在为我的公司开发一个网络应用程序。在此应用程序中,有一个表单,其中的输入字段包含有关联系人的信息。我想创建一个按钮,单击即可在地址簿中创建联系人。 是否可以使用 JavaScript 或其他网
在隐藏通讯录界面之前,是否可以一次选择多个联系人?还是每次地址簿界面出现时实际上只需要选择一个联系人? 最佳答案 是的,Whatsapp做到了。 如果您需要一个示例,请参见以下示例: MultiCon
我正在尝试获取 Android 中联系人的所有电话号码。我的代码如下所示: ContentResolver cr = context.getContentResolver(); String[] pr
我正在为域中的所有用户构建一个表。我让表格正常工作,并在其中为我的分页添加了一些代码,但现在我不断收到错误... //connection $conn = new mysqli($servername
我正在开发一个可以访问 iPhone 通讯录的应用程序。模拟器仅包含几个示例条目。我想找到一个包含数千个条目的示例地址簿字符集(英语、中文、阿拉伯语等)来全面测试我的应用程序。自己填写地址簿将花费永远
是否有任何 android API 可以提取 vcard 3.0 格式的联系人?我遇到了一个开源 vcard 项目 android-vcard 但在用法示例中提到了以下注释。 重要提示:如果您正在为
我的应用程序能够在应用程序的不同实例之间共享其内容,即有一个按钮可以让我将文档附加到电子邮件并将其发送给应用程序的另一个用户。当他们收到此文件时,它会在他们的应用程序实例中打开。这一切正常。 但是,在
我正在开发 iPhone 联系人管理应用程序。一位用户报告说他的所有联系人都是重复的。当他选择特定来源时,联系人不会重复。显然,这是因为他的地址簿同步了两次:一次是与他 PC 上的 iTunes 同步
我有两个继承自 UIViewController 的 Objective-C 类,我正在尝试一种不同的方法来学习如何与 iPhone 的地址簿进行交互。 example Apple 假设一切都在一个类
我想添加在 iOS 通讯录中保存联系人(电话号码、姓名、地址和电子邮件)的功能,方法是单击我的应用程序中的一个按钮!我该怎么做? 最佳答案 非常简单,只需按照以下步骤操作, 首先,您需要导入以下框架,
我正在使用新的 API 在我的手机上插入/更新联系人,我正在使用这种方法来更新它们.. String selectArgs1 = Data.CONTACT_ID + "=? AND " + Data.
我目前正在开发 Contact Importer 网络应用程序(使用 PHP),这样我就可以从 Gmail、Yahoo 等网站的用户帐户中获取电子邮件地址,并将它们用于我自己的邪恶目的。开个玩笑,我的
我与 Google 通讯录合作,一切顺利。但一个小时后,我需要手动刷新授予的访问权限。据此SO question我应该能够通过这个调用更新我的 refresh_token : refresh_toke
我正在使用以下代码获取 google 联系人姓名和电话号码。授权页面本身没有正常显示错误,如“您请求的页面无效”。 :( 请帮我解决这个问题... ` google.load("gdata",
正在尝试使用 google contacts api,如果我使用的话 https://www.google.com/m8/feeds/contacts/default/full 我有 25 个联系人,
由于 Google 停止了对旧版 Auth 的支持,现在我们必须使用 oAuth 2,我们简单的桌面应用程序无法再从我的 Google 帐户读取联系人。 很好 - 我明白这一点,但是这个新的 oAut
我想以编程方式将联系人直接保存到 iOS 设备的地址簿。 我该怎么做? 最佳答案 这是一个小例子: CFErrorRef error = NULL; NSLog(@"%@", [self descri
我正在尝试使用 Javascript 提取我在 Google 通讯录 ( https://contacts.google.com ) 上的联系人。为此,我需要将联系人面板滚动到底部,以便获取所有页面源
我目前正在开发一个 VoIP 应用程序,但我真的很受地址簿困扰。 由于自定义设计, native 地址簿不适合我的应用程序。此外,我想添加一些 native 地址簿中不存在的额外数据。但这会导致一些问
我是一名优秀的程序员,十分优秀!