我有一个命名空间让我们称为"专业",我想把我的sass资产放在里面app/assets/stylesheets/pro/sellers
.我有嵌套控制器cars
在里面sellers
.
在我的布局中,我有这个,stylesheet_link_tag params[:controller]
所以它是一般的.这会pro/sellers/cars.css.sass
为我的配置生成路径.
在sass文件中我想导入波旁文库,但是我收到此错误:
File to import not found or unreadable: ../functions/linear-gradient.
Load path: Sass::Rails::Importer(/my_project_path/app/assets/stylesheets/pro/sellers/cars.css.sass)
(in /my_project_path/app/assets/stylesheets/pro/sellers/cars.css.sass)
Run Code Online (Sandbox Code Playgroud)
是可以进行导入还是限制?
我在CoffeeScript中使用以下代码:
if elem in my_array
do_something()
Run Code Online (Sandbox Code Playgroud)
哪个编译成这个javascript:
if (__indexOf.call(my_array, elem) < 0) {
my_array.push(elem);
}
Run Code Online (Sandbox Code Playgroud)
我可以看到它使用了在脚本顶部定义的函数__indexOf.
我的问题是关于这个用例:我想从数组中删除一个元素,我想支持IE8.我可以做到这一点很容易indexOf
,并splice
在谁支持的浏览器indexOf
的的array
对象.但是,在IE8中,这不起作用:
if (attr_index = my_array.indexOf(elem)) > -1
my_array.splice(attr_index, 1)
Run Code Online (Sandbox Code Playgroud)
我尝试使用__indexOf
CoffeScript定义的函数,但我在编译器中得到一个保留字错误.
if (attr_index = __indexOf.call(my_array, elem) > -1
my_array.splice(attr_index, 1)
Run Code Online (Sandbox Code Playgroud)
那么我如何使用CoffeScript或者是否有更不引人注意的方法来调用indexOf?两次定义相同的函数似乎很奇怪,因为CoffeeScript不允许我使用他们的...
在Rails3中,有没有办法检查我现在呈现的页面是否是从同一个应用程序请求的,而不使用硬编码的域名?
我目前有:
def back_link(car_id = '')
# Check if search exists
uri_obj = URI.parse(controller.request.env["HTTP_REFERER"]) if controller.request.env["HTTP_REFERER"].present?
if uri_obj.present? && ["my_domain.com", "localhost"].include?(uri_obj.host) && uri_obj.query.present? && uri_obj.query.include?('search')
link_to '◀ '.html_safe + t('back_to_search'), url_for(:back) + (car_id.present? ? '#' + car_id.to_s : ''), :class => 'button grey back'
end
end
Run Code Online (Sandbox Code Playgroud)
但这并没有检查"www".在域名和所有其他可能的情况下.
如果我能找到上一页(引用者)中使用的特定控制器和操作,那也很好.
我想从邮件程序视图中访问一个方法,该视图返回一个布尔值,具体取决于发送电子邮件的用户.
例如,假设用户具有is_subscriber
可以为true或false 的属性.该方法将包含以下内容:
def show_banner?
FeatureManager.is_feature_available?(:subscription_banners) && !user.is_subscriber
end
Run Code Online (Sandbox Code Playgroud)
我想从邮件程序视图中访问此方法.
问题是,我的应用程序中有很多邮件程序(UserMailer,SubscriptionMailer,FollowUpMailer),并且每个邮件程序依赖于@user的实例变量似乎有点危险.
有没有办法可以从"到"字段访问电子邮件地址,如本例所示,我可以通过他的电子邮件地址找到用户:
mail :to => @user.email, :subject => I18n.t('welcome_mail.subject')
Run Code Online (Sandbox Code Playgroud)
这样做是一个好主意还是有更通用的方法来制作这样的辅助方法?
我想创建一个可以在加载页面后使用AJAX调用的通用控制器,并根据控制它的控制器更新页面上的不同内容.
目的是允许更好的页面和片段缓存,同时为用户显示自定义元素.
我的框架看起来像这样:
controllers/general_ajax_controller.rb
views/general_ajax/on_page_load.js.coffee
./_update_some_stuff.js.coffee
Run Code Online (Sandbox Code Playgroud)
on_page_load
控制器中的操作处理逻辑,确定要加载哪些部分,视图将呈现部分.
在on_page_load.js.coffee
视图中我有这个代码(简化):
<%= render "update_some_stuff" %>
Run Code Online (Sandbox Code Playgroud)
哪个应该呈现部分.相反,我得到这个错误:
ActionView::Template::Error (SyntaxError: Reserved word "function" on line 2):
app/views/general_ajax/on_page_load.js.coffee:1:in `_app_views_general_ajax_on_page_load_js_coffee___2304196970850216490_70321203283120'
Run Code Online (Sandbox Code Playgroud)
我认为coffeescript是在将它包含在视图中之前编译的(这是咖啡并且不支持编译的js)
如果我将on_page_load
视图的扩展名更改为.js.erb
然后它可以工作.(奇怪的是,我必须在它运行之前重启我的服务器,你知道为什么吗?)
你认为这是coffeescript中的问题还是不好的做法,因此不受支持?
作为一个侧面讨论,您如何看待我的动态编程方法?
我正在尝试为嵌套资源的控制器进行测试.
在routes.rb中嵌套是这样的
resources :cars, :only => [:index, :destroy, :show] do
resources :car_subscriptions, :only => [:new, :create], :as => :follow_subscriptions
end
Run Code Online (Sandbox Code Playgroud)
我正在尝试最具体地测试创建操作:
describe CarSubscriptionsController do
def valid_attributes
{:car_id => '1', :user_id => '2'}
end
describe "POST create" do
describe "with valid params" do
it "creates a new CarSubscription" do
expect {
post :create, :car_id => 1, :car_subscription => valid_attributes
}.to change(CarSubscription, :count).by(1)
end
it "assigns a newly created car_subscription as @car_subscription" do
post :create, :car_subscription => valid_attributes
assigns(:car_subscription).should be_a(CarSubscription)
assigns(:car_subscription).should be_persisted …
Run Code Online (Sandbox Code Playgroud) 在部分.js.coffee类型的视图中包含此代码(将其呈现为视图而不是资产):
<% if @followed_car_ids.present? %>
for car_id_and_path in <%= @followed_car_ids_and_paths.to_json %>
toggle_follow(car_id_and_path[0], true, car_id_and_path[1])
<% end %>
Run Code Online (Sandbox Code Playgroud)
在控制器中:
@followed_car_ids_and_paths = @followed_cars.map{|car| [car.id, url_for(current_user.car_subscriptions.find_by_car_id(car))]}
Run Code Online (Sandbox Code Playgroud)
请注意,是否在视图中放置地图(或收集)并不重要。如果我输入一个简单的字符串而不是也不起作用url_for(...
。
它给出了这个错误:
ActionView::Template::Error (Error: Parse error on line 1: Unexpected 'LOGIC'):
1: <% if @followed_car_ids.present? %>
2: for car_id_and_path in <%= @followed_car_ids_and_paths.to_json %>
3: toggle_follow(car_id_and_path[0], true, car_id_and_path[1])
4: <% end %>
app/views/general_ajax/_update_followed_cars.js.coffee:1:in `_app_views_general_ajax__update_followed_cars_js_coffee__3478461849674996439_70355260673980'
Run Code Online (Sandbox Code Playgroud)
当我=
从<%=
第2行中删除并在错误停止之前添加某种虚拟数组时:
for car_id_and_path in [1,2,3] <% @followed_car_ids_and_paths.to_json %>
Run Code Online (Sandbox Code Playgroud)
如果我使用平面数组(未使用map翻倍),则不会发生该错误:
for car_id_and_path in <%= @followed_car_ids %>
Run Code Online (Sandbox Code Playgroud)
都不是这样的:
for car_id_and_path …
Run Code Online (Sandbox Code Playgroud) 我正在使用这个D3教程条形图的修改版本.
什么是对我来说重要的是,动画不应该在离开然后在浏览器窗口触发所有的人都当窗口处于焦点再次叠加,导致浏览器挂起,那么按照这个建议,我尝试使用setTimeout
,而不是setInterval
应该在动画结束时调用.
我遇到了回调问题,我不明白为什么简单的transition()
回调是有效的,但不是enter()
例如.
设置图表和比例后,这是我的初始化函数的样子:
function redrawTimer() {
data.shift();
data.push(next());
redraw(function(){
console.log('callback');
setTimeout(redrawTimer, 1500);
});
}
setTimeout(redrawTimer, 1500);
function redraw(callback) {
var rect = chart.selectAll("rect")
.data(data, function(d) { return d.time; });
rect.enter().insert("rect")
.attr("x", function(d, i) { return x(i + 1) - .5; })
.attr("y", function(d) { return h - y(d.value) - .5; })
.attr("width", w)
.attr("height", function(d) { return y(d.value); })
.attr("fill", "white")
.attr("fill-opacity", 0.2)
.transition()
.duration(1000)
.attr("x", function(d, …
Run Code Online (Sandbox Code Playgroud) coffeescript ×3
javascript ×2
actionmailer ×1
animation ×1
arrays ×1
assets ×1
browser ×1
callback ×1
controller ×1
d3.js ×1
helper ×1
partials ×1
referrer ×1
rendering ×1
request ×1
routes ×1
rspec ×1
sass ×1
view ×1
views ×1