我有两个型号 - Banner和BannerType.
他们的架构如下所示:
旗帜
# Table name: banners
#
# id :integer not null, primary key
# name :string(255)
# image :string(255)
# created_at :datetime not null
# updated_at :datetime not null
# url :string(255)
# banner_type_id :integer
Run Code Online (Sandbox Code Playgroud)
BannerType
# Table name: banner_types
#
# id :integer not null, primary key
# name :string(255)
# created_at :datetime not null
# updated_at :datetime not null
Run Code Online (Sandbox Code Playgroud)
Banner belongs_to :banner_type 和 BannerType has_many :banners
我在BannerType中有两条记录:
BannerType.all
BannerType Load (0.3ms) …Run Code Online (Sandbox Code Playgroud) 我正在使用CanCanCan,Devise和Rolify.
我ApplicationController看起来像这样:
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
before_filter :new_post
rescue_from CanCan::AccessDenied do |exception|
redirect_to root_url, :alert => exception.message
end
def new_post
@post = Post.new
end
end
Run Code Online (Sandbox Code Playgroud)
我routes.rb看起来像这样:
authenticate :user, lambda { |u| u.has_role? :admin or :editor } do
get 'newsroom', to: 'newsroom#index', as: "newsroom"
get 'newsroom/published', to: 'newsroom#published'
get 'newsroom/unpublished', to: 'newsroom#unpublished'
end
# truncated for …Run Code Online (Sandbox Code Playgroud) 我有一个看起来像这样的初始部分调用:
<% events_array.each_with_index do |event, index| %>
<%= render partial: "events/activities/#{event.action}", locals: {event: event, index: index} %>
<section class="card-overlay valign-wrapper">
<div class="valign col s12 m6 l4 card-container">
<%= render partial: 'nodes/node', locals: {node: event.eventable.node, node_counter: index} %>
</div>
</section>
<% end %>
Run Code Online (Sandbox Code Playgroud)
这称为nodes/node部分(为简洁而截断):
<div class="col s12 m6 l4 card-container">
<div class="card" id="card-<%= node_counter %>">
<!-- Card Content -->
<div class="card-content" style="background-image: url('<%= node.media.try(:thumbnail_url) %>');">
Run Code Online (Sandbox Code Playgroud)
我现在在哪里收到此错误:
undefined local variable or method `node_counter' for #<#<Class:0x007f9067394f50>:0x007f9063b7d8b0>
Run Code Online (Sandbox Code Playgroud)
在这一行:
<div class="card" id="card-<%= node_counter …Run Code Online (Sandbox Code Playgroud) 我有一个样式表,我想在路径中的HTML电子邮件中使用:
app/vendor/assets/stylesheets/inspinia/email_templates/email-styles.css
我使用Premailer-Rails gem来制作电子邮件样式.
在我的mailer.html.erb布局中,我有以下内容:
<%= stylesheet_link_tag "inspinia/email_templates/email-styles.css", media: 'all' %>
Run Code Online (Sandbox Code Playgroud)
但是,在我的Heroku日志中,我收到以下消息:
app[web.1]: [923202d9-b3f1-4b9a-9f42-7b70dcc01d92] Started GET "/stylesheets/inspinia/email_templates/email-styles.css" for 54.167.56.21 at 2016-12-23 23:25:08 +0000
app[web.1]: [923202d9-b3f1-4b9a-9f42-7b70dcc01d92]
2016-12-23T23:25:08.286725+00:00 app[web.1]: [923202d9-b3f1-4b9a-9f42-7b70dcc01d92] ActionController::RoutingError (No route matches [GET] "/stylesheets/inspinia/email_templates/email-styles.css"):
Run Code Online (Sandbox Code Playgroud)
那么如何在生产中找出/指定此样式表的正确路径?
面包屑是导航元素,用于告诉用户他们在网站上的位置.
例如
首页>>项目>>阶段>>上传.
家庭,项目,阶段和上传是独立的控制者.
我刚刚更新至OS X Lion的,现在当我运行bundle update和bundle install,他们都失败的原因不尽相同.
Bundle Install给出了这个错误:
Using friendly_id (3.2.1.1)
Installing json (1.5.3) with native extensions /.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems/installer.rb:483:in `rescue in block in build_extensions': ERROR: Failed to build gem native extension. (Gem::Installer::ExtensionBuildError)
/.rvm/rubies/ruby-1.9.2-p0/bin/ruby extconf.rb
checking for re.h... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog …Run Code Online (Sandbox Code Playgroud) 很简单的问题,我有:
<%= f.submit %>
Run Code Online (Sandbox Code Playgroud)
我想申请class='btn'.我知道我可以轻松地做到这一点:
<%= f.submit 'Button Name', :class => 'btw' %>
Run Code Online (Sandbox Code Playgroud)
但是......我如何实现同样的目的,即应用一个类而不指定按钮的静态名称?
换句话说,鉴于我在部分表单中执行此操作,我希望按钮的名称根据被调用的操作(即new,create,update等)进行更改.那么我如何才能充分利用这两个世界呢?
我正在使用Octopress 3,当我运行时jekyll build,它会生成正确的文件集(包括我的静态文件,请参阅下面的文件列表):
$ cd _site
:_site$ ls -a
. CNAME assets google2d8.html index-alternative.html
.. about blog increase-revenue.html index.html
Run Code Online (Sandbox Code Playgroud)
请注意,我的整个jekyll生成blog现在安全地存储在内\blog\,这就是我想要的.
但是一旦我这样做octopress deploy,它会覆盖整个文件夹(也会覆盖我现有的静态文件),请参阅下面的列表:
$ cd _site
:_site$ ls -a
. .. Gemfile Gemfile.lock about css feed.xml index.html jekyll
Run Code Online (Sandbox Code Playgroud)
这是我的_config.yml:
title: My Title
email: some@email.com
description: > # this means to ignore newlines until "baseurl:"
some description
baseurl: "/blog" # the subpath of your site, e.g. /blog
url: "http://example.com" # the base …Run Code Online (Sandbox Code Playgroud) 当一个<blockquote>出现在我的div中时,我想覆盖它,以便它使用FontAwesome icon-quote-left而不是border-left: 5px rgb....它现在使用的值.
我怎么能用CSS做到这一点?
我不想使用JS - 因为它给页面增加了太多的负载.
我在我的Node模型上实现了PgSearch,如下所示:
include PgSearch
pg_search_scope :node_search, against: [:name, :user_id, :circa],
using: { tsearch: { any_word: true} },
:associated_against => {
comments: [:message],
user: [:first_name, :last_name, :email],
memberships: [:relation]
}
Run Code Online (Sandbox Code Playgroud)
在我的控制器中我有这个:
if params[:search]
@nodes = Node.node_search(params[:search])
end
Run Code Online (Sandbox Code Playgroud)
理想情况下,我希望能够做到的是,有人能够键入其中一个关联的文本表示(标志),并且只对该标志进行搜索过滤.
例如:"name:Bouncing Ball",搜索将name在nodes模型上调用的列上进行.Aka ...它会查找具有名称的所有节点,Bouncing Ball而不是搜索其他列或模型甚至任何关联.
当然,我希望能够执行以下搜索:(
owner: John Brown搜索其所有者/用户first_name和last_name是John Brown comment: Manhattan的所有节点),(搜索所有Manhattan在副本中都有文本注释的节点,等等上.
如何使用PgSearch实现这一目标?