我使用的是HTML5的地理位置为我的Rails应用程序,但是当我点击try it按钮,里面出现以下错误safari browser console下show web inspector console:
getLocation — localhost:83[blocked] Access to geolocation was blocked over insecure connection to http://localhost:3000.
Run Code Online (Sandbox Code Playgroud)
这是代码:
<button onclick="getLocation()">Try It</button>
<p id="demo"></p>
<script>
var x = document.getElementById("demo");
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
x.innerHTML = "Latitude: " + position.coords.latitude +
"<br>Longitude: " + position.coords.longitude;
}
</script>
Run Code Online (Sandbox Code Playgroud) 我在我的 rails 应用程序上使用cocoon gem,我在表单中有两个嵌套字段(类别、子类别)。最初我只显示第一个,第二个是隐藏的。每次第一个选择字段有子类别时,第二个字段都会填充并出现。
嵌套字段:
<div class="nested-fields">
<%= form.input :category, collection: @categories, as: :grouped_select, group_method: :children, :label => false, :include_blank => true, input_html: { id: "first_dropdown" } %>
<div class="show_hide">
<%= form.input :subcategories, label: false, :collection => [], :label_method => :name, :value_method => :id, required: true, input_html: { multiple: true, id: "second_dropdown" } %>
</div>
<div class="links">
<%= link_to_remove_association "Remove", form %>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
这是最初隐藏第二个字段的代码
$('#first_dropdown').keyup(function() {
if ($(this).val().length == 0) {
$('.show_hide').hide();
}
}).keyup();
Run Code Online (Sandbox Code Playgroud)
这是当第一个选择输入具有子类别时显示第二个选择输入的代码:
def select_item …Run Code Online (Sandbox Code Playgroud) 我在邮件中有这个:
attachments.inline["logo.png"] = File.read("#{Rails.root}/app/assets/images/logo.png")
Run Code Online (Sandbox Code Playgroud)
在电子邮件模板中,我有以下内容:
<%= image_tag attachments['logo.png'].url %>
Run Code Online (Sandbox Code Playgroud)
它工作正常,徽标确实出现在电子邮件中。
现在这是一个很奇怪的部分,我有另一个不在资产管道中但存储在数据库中的图像,以及一个循环存储在数据库中的其他图像。而且它们都没有出现在电子邮件中。电子邮件通过没有任何错误。任何想法可能有什么问题,我该如何调试?
<%= image_tag @account.image.thumb.url %>
<% @attachments.each do |attachment| %>
<%= image_tag attachment.images.thumb.url %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
I'm using the gem carrierwave to attach image and I uploading this version:
version :thumb do
process resize_to_fill: [1024, 768]
end
Run Code Online (Sandbox Code Playgroud) 我刚刚安装了devise gem,但出现以下错误:
Error:
AccountsControllerTest#test_should_update_account:
ActiveRecord::RecordNotUnique: SQLite3::ConstraintException: UNIQUE constraint failed: users.email: INSERT INTO "users" ("created_at", "updated_at", "id") VALUES ('2017-09-19 08:32:47.975048', '2017-09-19 08:32:47.975048', 298486374)
Run Code Online (Sandbox Code Playgroud)
这是我遵循的过程:
gem 'devise'
bundle install
rails generate devise:install
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
rails generate devise user
devise_for :users, path: 'users'
config.scoped_views = true
rails g devise:views users
rails generate devise:controllers users
Run Code Online (Sandbox Code Playgroud)
知道有什么问题吗?