我最近使用 HTML5、CSS3、JavaScript 和一些 jQuery 开发了我的第一个移动 Web 应用程序。在这个阶段,我想在 3 个不同的文件中分离 HTML、CSS 和 JS 的代码,并使用 Web 服务器在这些文件之间建立连接。有什么解决办法吗?
我正在尝试使用capistrano 3将我的ruby on rails 4项目部署到我的服务器中,但是我遇到了一些错误.
首先,当我这样做的时候
cap production deploy:check
Run Code Online (Sandbox Code Playgroud)
一切看起来都好!但是,当我这样做
cap production deploy
Run Code Online (Sandbox Code Playgroud)
我有两个错误:
DEBUG [e3cf53e3] Running [ -L /var/www/myapp/releases/20131026111326/public/assets ] on mydomain.com
DEBUG [e3cf53e3] Command: [ -L /var/www/myapp/releases/20131026111326/public/assets ]
DEBUG [e3cf53e3] Finished in 0.104 seconds with exit status 1 (failed).
DEBUG [304388e5] Running [ -d /var/www/myapp/releases/20131026111326/public/assets ] on mydomain.com
DEBUG [304388e5] Command: [ -d /var/www/myapp/releases/20131026111326/public/assets ]
DEBUG [304388e5] Finished in 0.104 seconds with exit status 1 (failed).
Run Code Online (Sandbox Code Playgroud)
我得到的最后一个错误是:
DEBUG [4e4c65ef] rake aborted!
DEBUG [4e4c65ef] Unknown …Run Code Online (Sandbox Code Playgroud) 我在ubuntu上成功安装了enthought Python(在Amazon EC2实例中运行).但是,在尝试安装lxml软件包时出现以下错误(已插入日志)
/usr/local/bin/pip run on Sat Mar 30 22:05:14 2013
Downloading/unpacking lxml
Running setup.py egg_info for package lxml
/usr/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'bugtrack_url'
warnings.warn(msg)
Building lxml version 3.1.1.
Building without Cython.
Using build configuration of libxslt 1.1.26
Building against libxml2/libxslt in the following directory: /usr/lib/x86_64-linux-gnu
running egg_info
writing pip-egg-info/lxml.egg-info/PKG-INFO
writing top-level names to pip-egg-info/lxml.egg-info/top_level.txt
writing dependency_links to pip-egg-info/lxml.egg-info/dependency_links.txt
warning: manifest_maker: standard file '-c' not found
reading manifest file 'pip-egg-info/lxml.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
warning: no files found matching …Run Code Online (Sandbox Code Playgroud) 我想获取在博客应用程序中创建文章的用户的用户名或电子邮件(都在用户表中).目前,我可以从articles_controller.rb获取用户ID
def create
@article = Article.new(params[:article])
@article.user_id = current_user.id
@article.save
redirect_to article_path(@article)
end
Run Code Online (Sandbox Code Playgroud)
但不知道如何获取用户名或电子邮件.基本上我想在文章索引页面上显示用户名或电子邮件.请建议我如何完成它
user.rb
class User < ActiveRecord::Base
has_many :articles
has_many :comments
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable,
# :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
attr_accessible :username, :email, :password, :password_confirmation, :remember_me
attr_accessible :title, :body
end
Run Code Online (Sandbox Code Playgroud)
article.rb
class Article < ActiveRecord::Base
attr_accessible :title, :body
has_many :comments
belongs_to :user
end
Run Code Online (Sandbox Code Playgroud)
articles_controller.rb
class …Run Code Online (Sandbox Code Playgroud) class User < ActiveRecord::Base
attr_accessor :password
Rails.logger.info "xxy From outside"
def before_create
Rails.logger.info "xxy From inside the before_create"
end
end
Run Code Online (Sandbox Code Playgroud)
在调用User.save控制器时,我的开发日志会启动,xxy From outside但不是xxy From inside the before_create这样我认为它已经被弃用了吗?
如果是这样,我怎样才能在保存之前调用模型方法?或者已xxy From outside记录,这是否意味着在保存模型实例时会自动调用所有方法?
我正在尝试处理一个有点复杂的查询.我已经阅读了一些关于如何处理这个问题的方法,但它们并没有真正适用于此,因为这不像一个复杂的搜索表单(如在vBulletin搜索帖表单上),而是一组过滤两者的路由按"类别"(未发布,流行,最新)和"时间"(所有时间,上个月,上周,今天)
我意识到下面的代码非常糟糕.我的目标只是让它工作,然后重构.更不用说,它甚至没有真正起作用,因为它没有考虑两种类型和时间,只考虑其中一种,但我想我会在这个线程中处理它.
另外,为了使这个SO代码粘贴更清楚,我.page(params[:page]).per(30)从每一行中排除了它,但是它需要继续所有这些.
那么,有谁知道我会怎么做呢?我已经仔细考虑了一段时间而且有点难过
def index
case params[:category]
when "latest"
@books = Book.all.page(params[:page]).per(30)
when "downloads"
@books = Book.order('downloads DESC')
when "top100"
@books = Book.order('downloads DESC').limit(100)
when "unreleased"
@books = Book.unreleased
else
@books = Book.all.page(params[:page]).per(30)
end
case params[:time]
when "today"
@books = Book.days_old(1)
when "week"
@books = Book.days_old(7)
when "month"
@books = Book.days_old(30)
when "all-time"
@books = Book.all
else
@books = Book.all.page(params[:page]).per(30)
end
end
Run Code Online (Sandbox Code Playgroud)
路线:
# Books
get 'book/:id', to: 'books#show', as: 'book'
resources :books, only: [:index] do
get …Run Code Online (Sandbox Code Playgroud) refactoring ruby-on-rails ruby-on-rails-4 rails-activerecord
我有一些我正在使用的扭曲文本,由http://csswarp.eleqtriq.com/生成.它为warping创建了所有的CSS和HTML,我用一个<a>标签来包装跨度,该标签的类用于样式和jquery函数.
问题是,如果我换的跨度<a>,这是我需要的,因为这些扭曲的文字是我的链接,所有的造型(定位最重要的),刚刚消失......如果我删除从跨度包装,风格可以追溯到正常,它看起来扭曲等..
我在这里为我的问题编写了jsfiddle,http://jsfiddle.net/WJDwP/2/.
我想创建一个路径product/:id/monthly/revenue/,并product/:id/monthly/items_sold和等效命名路由product_monthly_revenue和product_monthly_items_sold,这些路由只会显示图表.我试过了
resources :products do
scope 'monthly' do
match 'revenue', to: "charts#monthly_revenue", via: 'get'
match 'items_sold', to: "charts#monthly_items_sold", via: 'get'
end
end
Run Code Online (Sandbox Code Playgroud)
但这给了我路线:
product_revenue GET /monthly/products/:product_id/revenue(.:format) charts#monthly_revenue
product_items_sold GET /monthly/products/:product_id/items_sold(.:format) charts#monthly_items_sold
Run Code Online (Sandbox Code Playgroud)
其中monthly在前面被所附代替,以及路线命名是关闭的.我知道我可以这样做:
resources :products do
match 'monthly/revenue', to: "charts#monthly_revenue", via: 'get', as: :monthly_revenue
match 'monthly/items_sold', to: "charts#monthly_items_sold", via: 'get', as: :monthly_items_sold
end
Run Code Online (Sandbox Code Playgroud)
但这不是DRY,当我尝试添加更多像年度这样的类别时会变得很疯狂.当我想将所有图表合并到一个控制器中时,使用命名空间会强制我为每个命名空间创建一个新控制器.
所以我想总结的问题是:是否可以在没有namspacing控制器的情况下命名路由?或者是否可以合并命名路线类别的创建?
编辑:使用
resources :products do
scope "monthly", as: :monthly, path: "monthly" do
match 'revenue', to: "charts#monthly_revenue", via: …Run Code Online (Sandbox Code Playgroud) 这听起来像一个简单的问题,但由于某种原因,我迷路了.
在我的用户个人资料页面中,我正在显示他们的所有帖子.如果他们有3个帖子,我想展示这样的东西.
1. Post one title
2. Post two title
3. Post three title
Run Code Online (Sandbox Code Playgroud)
所以它显示了帖子左边的数字.这不能是帖子的ID.有谁知道如何解决这个问题?
css ×2
html ×2
amazon-ec2 ×1
associations ×1
capistrano ×1
css3 ×1
enthought ×1
javascript ×1
jquery ×1
lxml ×1
mobile ×1
python ×1
refactoring ×1
ruby ×1
ubuntu ×1