我使用 Assets 样式表加载了一个 css。但是它只加载索引。当我使用 f12 时,控制台会显示 index.html 以外的其他页面的 URL。使用默认布局 application.html.erb 添加/cloths iam
路线.rb
Rails.application.routes.draw do
resources :categories
resources :cloths
end
cloths_controller.rb
class ClothsController < ApplicationController
before_action :set_cloth, only: [:show, :edit, :update, :destroy]
# GET /cloths
# GET /cloths.json
def index
@cloths = Cloth.all
@categories = Category.all
end
# GET /cloths/1
# GET /cloths/1.json
def show
@cloths = Cloth.all
@comments = Comment.where("cloth_id = ?", @cloth.id)
@comments = Comment.paginate(:page => params[:page], :per_page => 3)
end
# GET /cloths/new
def new
@cloth = Cloth.new
@categories = Category.all
respond_to do|format|
format.html #new.html.erb
format.xml{render :xml=>@recipe}
end
end
# GET /cloths/1/edit
def edit
end
# POST /cloths
# POST /cloths.json
def create
@cloth = Cloth.new(cloth_params)
respond_to do |format|
if @cloth.save
format.html { redirect_to @cloth, notice: 'Cloth was successfully created.' }
format.json { render :show, status: :created, location: @cloth }
else
format.html { render :new }
format.json { render json: @cloth.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /cloths/1
# PATCH/PUT /cloths/1.json
def update
respond_to do |format|
if @cloth.update(cloth_params)
format.html { redirect_to @cloth, notice: 'Cloth was successfully updated.' }
format.json { render :show, status: :ok, location: @cloth }
else
format.html { render :edit }
format.json { render json: @cloth.errors, status: :unprocessable_entity }
end
end
end
# DELETE /cloths/1
# DELETE /cloths/1.json
def destroy
@cloth.destroy
respond_to do |format|
format.html { redirect_to cloths_url, notice: 'Cloth was successfully destroyed.' }
format.json { head :no_content }
end
end
def men
end
#PRIVATE
private
# Use callbacks to share common setup or constraints between actions.
def set_cloth
@cloth = Cloth.find(params[:id])
end
def cloth_params
params.require(:cloth).permit(:title, :category_id, :description)
end
end
应用程序.html.erb
<!DOCTYPE HTML>
<html>
<head>
<title>Batik</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="assets/bootstrap.css" rel='stylesheet' type='text/css' />
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="assets/simpleCart.min.js"> </script>
<script src="assets/jquery.min.js"></script>
<!-- Custom Theme files -->
<link href="assets/style.css" rel='stylesheet' type='text/css' />
<!-- Custom Theme files -->
<!--webfont-->
<link href='http://fonts.googleapis.com/css?family=Raleway:100,200,300,400,500,600,700,800,900' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Audiowide' rel='stylesheet' type='text/css'>
<script src="assets/jquery.easydropdown.js"></script>
<!-- Add fancyBox main JS and CSS files -->
<script src="assets/jquery.magnific-popup.js" type="text/javascript"></script>
<link href="assets/magnific-popup.css" rel="stylesheet" type="text/css">
<script>
$(document).ready(function() {
$('.popup-with-zoom-anim').magnificPopup({
type: 'inline',
fixedContentPos: false,
fixedBgPos: true,
overflowY: 'auto',
closeBtnInside: true,
preloader: false,
midClick: true,
removalDelay: 300,
mainClass: 'my-mfp-zoom-in'
});
});
</script>
</head>
<body>
<%#=debug(session)%>
<%= yield %>
<!--Footer-->
<div class="container">
<div class="brands">
<ul class="brand_icons">
<li><img src='assets/icon1.jpg' class="img-responsive" alt=""/></li>
<li><img src='assets/icon2.jpg' class="img-responsive" alt=""/></li>
<li><img src='assets/icon3.jpg' class="img-responsive" alt=""/></li>
<li><img src='assets/icon4.jpg' class="img-responsive" alt=""/></li>
<li><img src='assets/icon5.jpg' class="img-responsive" alt=""/></li>
<li><img src='assets/icon6.jpg' class="img-responsive" alt=""/></li>
<li class="last"><img src='assets/icon7.jpg' class="img-responsive" alt=""/></li>
</ul>
</div>
</div>
<div class="container">
<div class="instagram_top">
<div class="instagram text-center">
<h3><i class="insta_icon"> </i> Instagram feed: <span class="small">#Surfhouse</span></h3>
</div>
<ul class="instagram_grid">
<li><a class="popup-with-zoom-anim" href="#small-dialog1"><img src="assets/i1.jpg" class="img-responsive"alt=""/></a></li>
<li><a class="popup-with-zoom-anim" href="#small-dialog1"><img src="assets/i2.jpg" class="img-responsive" alt=""/></a></li>
<li><a class="popup-with-zoom-anim" href="#small-dialog1"><img src="assets/i3.jpg" class="img-responsive" alt=""/></a></li>
<li><a class="popup-with-zoom-anim" href="#small-dialog1"><img src="assets/i4.jpg" class="img-responsive" alt=""/></a></li>
<li><a class="popup-with-zoom-anim" href="#small-dialog1"><img src="assets/i5.jpg" class="img-responsive" alt=""/></a></li>
<li class="last_instagram"><a class="popup-with-zoom-anim" href="#small-dialog1"><img src="assets/i6.jpg" class="img-responsive" alt=""/></a></li>
<div class="clearfix"></div>
<div id="small-dialog1" class="mfp-hide">
<div class="pop_up">
<h4>A Sample Photo Stream</h4>
<img src="assets/i_zoom.jpg" class="img-responsive" alt=""/>
</div>
</div>
</ul>
</div>
<ul class="footer_social">
<li><a href="#"> <i class="fb"> </i> </a></li>
<li><a href="#"><i class="tw"> </i> </a></li>
<li><a href="#"><i class="pin"> </i> </a></li>
<div class="clearfix"></div>
</ul>
</div>
</div>
</body>
</html>
在 Index.html 上一切正常,但在显示、编辑和添加所有 Assets url 时变得不同。像这样
GET http://localhost:3000/cloths/assets/bootstrap.css (404 could not found)
为什么 URL 突然变成“/cloths/assets”而不是“/assets”
最佳答案
你需要添加config.assets.paths << Rails.root.join('app', 'assets', 'cloths')给你的config/application.rb使布料/ Assets 可以从您的应用程序上的/assets 访问
关于html - 我的 css Assets URL 使用 rails 在不同的页面中突然发生变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36685682/
我正在学习如何使用Nokogiri,根据这段代码我遇到了一些问题:require'rubygems'require'mechanize'post_agent=WWW::Mechanize.newpost_page=post_agent.get('http://www.vbulletin.org/forum/showthread.php?t=230708')puts"\nabsolutepathwithtbodygivesnil"putspost_page.parser.xpath('/html/body/div/div/div/div/div/table/tbody/tr/td/div
我有一个Ruby程序,它使用rubyzip压缩XML文件的目录树。gem。我的问题是文件开始变得很重,我想提高压缩级别,因为压缩时间不是问题。我在rubyzipdocumentation中找不到一种为创建的ZIP文件指定压缩级别的方法。有人知道如何更改此设置吗?是否有另一个允许指定压缩级别的Ruby库? 最佳答案 这是我通过查看rubyzip内部创建的代码。level=Zlib::BEST_COMPRESSIONZip::ZipOutputStream.open(zip_file)do|zip|Dir.glob("**/*")d
类classAprivatedeffooputs:fooendpublicdefbarputs:barendprivatedefzimputs:zimendprotecteddefdibputs:dibendendA的实例a=A.new测试a.foorescueputs:faila.barrescueputs:faila.zimrescueputs:faila.dibrescueputs:faila.gazrescueputs:fail测试输出failbarfailfailfail.发送测试[:foo,:bar,:zim,:dib,:gaz].each{|m|a.send(m)resc
很好奇,就使用rubyonrails自动化单元测试而言,你们正在做什么?您是否创建了一个脚本来在cron中运行rake作业并将结果邮寄给您?git中的预提交Hook?只是手动调用?我完全理解测试,但想知道在错误发生之前捕获错误的最佳实践是什么。让我们理所当然地认为测试本身是完美无缺的,并且可以正常工作。下一步是什么以确保他们在正确的时间将可能有害的结果传达给您? 最佳答案 不确定您到底想听什么,但是有几个级别的自动代码库控制:在处理某项功能时,您可以使用类似autotest的内容获得关于哪些有效,哪些无效的即时反馈。要确保您的提
这似乎应该有一个直截了当的答案,但在Google上花了很多时间,所以我找不到它。这可能是缺少正确关键字的情况。在我的RoR应用程序中,我有几个模型共享一种特定类型的字符串属性,该属性具有特殊验证和其他功能。我能想到的最接近的类似示例是表示URL的字符串。这会导致模型中出现大量重复(甚至单元测试中会出现更多重复),但我不确定如何让它更DRY。我能想到几个可能的方向...按照“validates_url_format_of”插件,但这只会让验证干给这个特殊的字符串它自己的模型,但这看起来很像重溶液为这个特殊的字符串创建一个ruby类,但是我如何得到ActiveRecord关联这个类模型
假设我做了一个模块如下:m=Module.newdoclassCendend三个问题:除了对m的引用之外,还有什么方法可以访问C和m中的其他内容?我可以在创建匿名模块后为其命名吗(就像我输入“module...”一样)?如何在使用完匿名模块后将其删除,使其定义的常量不再存在? 最佳答案 三个答案:是的,使用ObjectSpace.此代码使c引用你的类(class)C不引用m:c=nilObjectSpace.each_object{|obj|c=objif(Class===objandobj.name=~/::C$/)}当然这取决于
我的目标是转换表单输入,例如“100兆字节”或“1GB”,并将其转换为我可以存储在数据库中的文件大小(以千字节为单位)。目前,我有这个:defquota_convert@regex=/([0-9]+)(.*)s/@sizes=%w{kilobytemegabytegigabyte}m=self.quota.match(@regex)if@sizes.include?m[2]eval("self.quota=#{m[1]}.#{m[2]}")endend这有效,但前提是输入是倍数(“gigabytes”,而不是“gigabyte”)并且由于使用了eval看起来疯狂不安全。所以,功能正常,
作为我的Rails应用程序的一部分,我编写了一个小导入程序,它从我们的LDAP系统中吸取数据并将其塞入一个用户表中。不幸的是,与LDAP相关的代码在遍历我们的32K用户时泄漏了大量内存,我一直无法弄清楚如何解决这个问题。这个问题似乎在某种程度上与LDAP库有关,因为当我删除对LDAP内容的调用时,内存使用情况会很好地稳定下来。此外,不断增加的对象是Net::BER::BerIdentifiedString和Net::BER::BerIdentifiedArray,它们都是LDAP库的一部分。当我运行导入时,内存使用量最终达到超过1GB的峰值。如果问题存在,我需要找到一些方法来更正我的代
我正在尝试使用ruby和Savon来使用网络服务。测试服务为http://www.webservicex.net/WS/WSDetails.aspx?WSID=9&CATID=2require'rubygems'require'savon'client=Savon::Client.new"http://www.webservicex.net/stockquote.asmx?WSDL"client.get_quotedo|soap|soap.body={:symbol=>"AAPL"}end返回SOAP异常。检查soap信封,在我看来soap请求没有正确的命名空间。任何人都可以建议我
在我的Rails(2.3,Ruby1.8.7)应用程序中,我需要将字符串截断到一定长度。该字符串是unicode,在控制台中运行测试时,例如'א'.length,我意识到返回了双倍长度。我想要一个与编码无关的长度,以便对unicode字符串或latin1编码字符串进行相同的截断。我已经了解了Ruby的大部分unicode资料,但仍然有些一头雾水。应该如何解决这个问题? 最佳答案 Rails有一个返回多字节字符的mb_chars方法。试试unicode_string.mb_chars.slice(0,50)