我正在尝试创建一个可重复使用的远程模态.我们的想法是创建一个模型容器并在其中呈现内容yield
并在需要时呈现内容.
注意:所有HTML
代码都将被写入HAML
.我正在使用bootstrap-modal-rails gem来处理我的模态.
我的模态容器布局(不是部分):
%div(class="modal" id="mainModal ajax-modal" tabindex="-1" role="dialog"){:'aria-labelledby'=>"mainModalLabel", :'aria-hidden'=>"true"}
%div(class="c-modal__container")
%div(class="c-modal__layout modal__content")
= yield
Run Code Online (Sandbox Code Playgroud)
在我的application.html.haml
,我有一个div定义模态位置如下:
-# ...
%div(id="modal-holder")
- unless params[:nojs]
= javascript_include_tag 'desktop'
-# ...
Run Code Online (Sandbox Code Playgroud)
这是我的问题来自哪里.我有一个book controller
用户可以添加书籍的地方.我有一个多步注册,我的new
行动必须是我的模式.当用户点击New book
链接时,我正在加载一个新模式.
我的New book
链接:
= link_to "New book", new_book_path, class: "c-link--navbar", data: { modal: true }
Run Code Online (Sandbox Code Playgroud)
CoffeeScript的(重新写入jQuery
)的模式(此代码这篇文章):
$(function() {
var modal_holder_selector, modal_selector;
modal_holder_selector = '#modal-holder';
modal_selector = '.modal';
$(document).on('click', 'a[data-modal]', function() …
Run Code Online (Sandbox Code Playgroud) 我试图jquery ui autocomplete
在我的远程模式中实现它不起作用,而autocomplete
在常规静态页面上工作.
对于远程模态,我使用宝石的组合:modal-responder-rails和rails-bootstrap-modal
这是我的autocomplete
代码:
jQuery(function() {
var data = $('#book_subcategory_name').data('autocomplete-source');
var NoResultsLabel = "No Results";
return $('[id*="book_subcategory_name"]').autocomplete({
delay: 0,
position: {
my: "left+0 top+4"
},
source: function(request, response) {
var results = $.ui.autocomplete.filter(data, request.term);
if (!results.length) {
results = [NoResultsLabel];
}
response(results);
},
select: function (event, ui) {
if (ui.item.label === NoResultsLabel) {
event.preventDefault();
}
},
focus: function (event, ui) {
if (ui.item.label === NoResultsLabel) {
event.preventDefault();
}
}
}); …
Run Code Online (Sandbox Code Playgroud) 我正在与Devise gem合作,并show
为用户创建了一个页面。我的想法是制作一个简单的路径www.website.com/:id
,我将其配置如下:
devise_for :users, path: '', path_names: {sing_in: "login", sing_out:
"signout", sing_up: "signup", edit: "edit"},
:controllers => {:registrations => :registrations }
resources :users, only: [:show]
get '/:id' => 'users#show', as: :profile
Run Code Online (Sandbox Code Playgroud)
我的路线工作正常,但除了show
页面之外,我还有页面static controller
,例如about
页面。我希望能够像访问它一样访问它www.website.com/about
,这是我定义我的方式static routes
:
get '/about', to: 'static#about'
Run Code Online (Sandbox Code Playgroud)
现在,如果我尝试重定向到about page
,则会收到错误消息:
ActiveRecord::RecordNotFound in UsersController#show
Couldn't find User with 'id'=about
Run Code Online (Sandbox Code Playgroud)
这是我的users_controller.rb
:
class UsersController < ApplicationController
def show
@user = User.find_by_id(params[:id])
@services = …
Run Code Online (Sandbox Code Playgroud) rails server
由于以下错误,我无法运行命令:
为数据库适配器指定了“sqlite3”,但未加载 gem。添加
gem 'sqlite3'
到您的 Gemfile(并确保其版本为 ActiveRecord 要求的最低版本)。(宝石::加载错误)
我在 Google 中找到了几个答案(将 Sqlite3 更改为 Postgresql Rails,Ruby on Rails -“将 'gem sqlite3''添加到您的 Gemfile”,将 'gem sqlite3' 添加到您的 Gemfile ...)但这些答案都不适合我。我尝试手动更改gemfile.lock
值,尝试运行bundle
命令但仍然遇到相同的错误。此外,我确实sqlite3
在我的gemfile
下属:development, :test
小组中。
macOS Mojave Version 10.14.4 Beta
sqlite3
版本:1.4.0pg
版本:0.20PS:我使用pg
gem 是为了在 heroku 上使用数据库。
这是我的gemfile
,请注意,其中一些gems
被删除以使列表看起来更小更干净:
group :production do
# Database
gem 'pg', '~> 0.20'
gem 'rails_12factor'
end …
Run Code Online (Sandbox Code Playgroud) 我有颜色变量(示例):
// _colors.scss
:root, * {
--color-primary-50: 1,1,1;
--color-primary-100: 2,2,2;
--color-primary-200: 3,3,3;
}
Run Code Online (Sandbox Code Playgroud)
我想根据变量生成类,例如:
// _background.scss
.bg-primary-50 {
background: rgb(var(--color-primary-50));
}
.bg-primary-100 {
background: rgb(var(--color-primary-100));
}
.bg-primary-200 {
background: rgb(var(--color-primary-200));
}
Run Code Online (Sandbox Code Playgroud)
如果我需要更改或添加新颜色并_background
使用基于_colors
变量的类动态填充我的文件,我想简化未来的修改。
这似乎是很多单调的工作。有什么办法可以得到这个结果吗?也许我应该改变我的文件结构?