嗨我想用jQuery逐步改变页面的字体大小我该怎么做?
就像是:
$('body').css({'font-size':'+.01px'});
$('body').css({'font-size':'-.01px'});
Run Code Online (Sandbox Code Playgroud) 我有一个博客.在单个帖子页面上,我想显示前一个链接,如果有,则在底部发布下一个帖子.该链接应该是特定帖子的标题.
我如何用Mongoose最简单的方法呢?
我当前的控制器看起来像这样:
Post.findOne { slug : req.params.slug }, (err, post) ->
res.render "blog/show.jade", locals: title: "This post", post: post
Run Code Online (Sandbox Code Playgroud)
架构看起来像这样:
PostSchema = new Schema(
title:
type: String
required: true
index: true
preamble: String
body: String
slug: String
createdAt: Date
updatedAt: Date
)
Run Code Online (Sandbox Code Playgroud) 我的app.coffee看起来像这样:
connect = require 'connect'
express = require 'express'
jade = require 'jade'
stylus = require 'stylus'
app = express.createServer()
# CONFIGURATION
app.configure(() ->
app.set 'view engine', 'jade'
app.set 'views', "#{__dirname}/views"
app.use connect.bodyParser()
app.use connect.static(__dirname + '/public')
app.use express.cookieParser()
app.use express.session({secret : "shhhhhhhhhhhhhh!"})
app.use express.logger()
app.use express.methodOverride()
app.use app.router
app.use stylus.middleware({
force: true
src: "#{__dirname}/views"
dest: "#{__dirname}/public/css"
compress: true
})
)
# ROUTES
app.get '/', (req, res) ->
res.render 'index',
locals:
title: 'Title'
# SERVER
app.listen(1234)
console.log "Express server listening …
Run Code Online (Sandbox Code Playgroud) 如何获取所有"链接"条目,并删除那些空白的"网址"列?我的控制器看起来像这样:
def show
@user = User.find_by_username(params[:username])
@links = @user.links.all
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @links }
end
end
Run Code Online (Sandbox Code Playgroud)
提前致谢!
编辑#1
如果我做:
@links = @user.all(:conditions => 'url != NULL')
Run Code Online (Sandbox Code Playgroud)
我收到一个错误:
NoMethodError in UsersController#show
undefined method `all' for #<User:0x2254f98>
Run Code Online (Sandbox Code Playgroud)
如果我这样做:
@links = @user.links.all(:conditions => 'url != NULL')
Run Code Online (Sandbox Code Playgroud)
我仍然获得所有链接,即使是那些有空网址的链接......
编辑#2
如果我做
@links = User.all(:conditions => 'url != NULL')
Run Code Online (Sandbox Code Playgroud)
我明白了
ActiveRecord::StatementInvalid in UsersController#show
SQLite3::SQLException: no such column: url: SELECT * FROM "users" WHERE (url != NULL)
Run Code Online (Sandbox Code Playgroud)
如果我这样做
@links …
Run Code Online (Sandbox Code Playgroud) 有没有办法打开换行符?它在调试时很有用.
我知道这个话题(源代码中的Node.js JADE换行符吗?)说由于性能不好,但在开发时在本地机器上说它应该不是问题.
我有一个名为profile的命名路由,我希望能够以json的身份访问它.但是当我查看我的rake路由输出时,我发现缺少(.:格式).如何将其添加到命名路线?
user GET /users/:id(.:format) {:action=>"show", :controller=>"users"}
profile /:username {:action=>"show", :controller=>"users"}
Run Code Online (Sandbox Code Playgroud)
提前致谢!
在Ruby/Sinatra/Haml中,我写道:
%html{:lang => 'en'}
%head
%meta{:charset => 'utf-8'}
%title= @title
%body
=yield
Run Code Online (Sandbox Code Playgroud)
Node/Express/Jade会是什么样子?
更新:我找到了解决方案,请查看本页底部...
我有一个用CoffeScript编写的Node.js,Express,MongoDB,Mongoose项目,我可以创建和读取数据,但我无法更新.
这就是我的代码的样子;
app.js
# update
app.put "/admin/:id.:format?", (req, res) ->
Content.findById req.body.content.id, (err, c) ->
c.title = req.body.content.title
c.body = req.body.content.body
c.save (err) ->
switch req.params.format
when "json"
res.send c.__doc
else
res.redirect "/admin"
Run Code Online (Sandbox Code Playgroud)
edit.jade
h2 Edit Content
form(method='post', action='/admin/' + c.id)
input(name='content[id]', value=c.id, type='hidden')
input(name='_method', value='PUT', type='hidden')
div
label Title:
input(name='content[title]', value=c.title || '')
div
label Body:
textarea(name='content[body]')=c.body || ''
div
input(type='submit', value='Save')
Run Code Online (Sandbox Code Playgroud)
这就是我的控制台所说的
127.0.0.1 - - [Thu, 13 Oct 2011 21:39:55 GMT] "POST /admin/4e96ec17fd7da7cb18000001 HTTP/1.1" 404 - …
Run Code Online (Sandbox Code Playgroud) 我有一个非常简单的Rails 3应用程序,其中包含由Devise和Notes模型运行的用户模型.现在,网址和路由如下所示:
# url
/users/MEMBERNAME/notes/TITLE-OF-NOTE
# routing
resources :users do
resources :notes
end
Run Code Online (Sandbox Code Playgroud)
但我希望网址看起来像这样,在这种情况下,路由怎么样?
# url
/MEMBERNAME/TITLE-OF-NOTE
Run Code Online (Sandbox Code Playgroud)
更新:
谢谢,现在我发现了一个新问题.在我的表格中我有这个代码:
<%= form_for([@user, @note]) do |f| %>
Run Code Online (Sandbox Code Playgroud)
在我的控制器中,我重定向如下:
format.html { redirect_to([@user, @note], :notice => 'Note was successfully created.') }
Run Code Online (Sandbox Code Playgroud)
在这两种情况下,当我使用@user时,@ note旧的URL仍然存在.您知道如何翻译表单和重定向以使用成员/标题结构吗?
提前致谢!
我有一个sinatra应用程序,我计划在飞行中制作一个油炸的网址.我有一个看起来像这样的正则表达式的函数,但它不会将'空格'转换为'破折号',''转换为' - '.
def self.make_slug(title)
title.downcase.gsub(/ /, '-').gsub(/[^a-z0-9_]/, '').squeeze('-')
end
Run Code Online (Sandbox Code Playgroud)
提前致谢!
更新
现在我也试图将åä改为a和ö到o,我的代码看起来像这样但不起作用,任何想法?
gsub(/[åä]/, 'a')
gsub(/[ö]/, 'o')
Run Code Online (Sandbox Code Playgroud)