小编Nic*_*nto的帖子

在Rails中重命名会话cookie

因为我希望会话cookie反映网址而不是应用名称,我想重命名cookie.

调用当前会话cookie名称 _APPNAME_session

有没有办法将其重命名为_somethingelse_session

当我这样做的时候,我会看到它的名字

curl -i <appurl>
Run Code Online (Sandbox Code Playgroud)

我知道了

set_cookie = _APPNAME_session=....
Run Code Online (Sandbox Code Playgroud)

cookies rack session-cookies ruby-on-rails-3 ruby-on-rails-3.1

6
推荐指数
1
解决办法
3229
查看次数

用sed中的单个选项卡替换选项卡

我想用sed的单个选项卡替换所有多个选项卡.我正在尝试使用

sed 's:\t+:\t:' .\text.CSV > newtext.csv
Run Code Online (Sandbox Code Playgroud)

但这似乎不起作用

如果我在崇高中打开并用正则表达式替换它\t+,\t它可以正常工作

我的sed出了什么问题?

另外,如果我用逗号替换制表符

sed 's:\t\t*:,:g' text.CSV > newtext.csv
Run Code Online (Sandbox Code Playgroud)

我得到这种线

264262360,20030826,200308,2003,2003.6466,BUS,EMPLOYER,,,,,,BUS,,, ,,,,,,,,,,0,051,051,05,1,3.4,12,2,12,5.24866163479182,1
Run Code Online (Sandbox Code Playgroud)

regex windows sed

6
推荐指数
2
解决办法
1万
查看次数

正则表达式 - 仅当组存在时才捕获,如果不存在则忽略

我有这个正则表达式

(\w+)\s*\:\s*(\W\d+)
Run Code Online (Sandbox Code Playgroud)

设置为匹配类似的东西

"price: $200"
Run Code Online (Sandbox Code Playgroud)

我需要做什么来改变它,以便它匹配"price: $200""$200"(如果价格:部分不存在)

我试过

(?:(\w+)\s*\:\s*)*(\W\d+)
Run Code Online (Sandbox Code Playgroud)

但这不起作用,因为它给了我第一个空匹配

regex

6
推荐指数
1
解决办法
1万
查看次数

覆盖设计密码控制器

我想禁用

  def create
    self.resource = resource_class.send_reset_password_instructions(resource_params)

    if successfully_sent?(resource)
      respond_with({}, :location => after_sending_reset_password_instructions_path_for(resource_name))
    else
      respond_with(resource)
    end
  end
Run Code Online (Sandbox Code Playgroud)

因此在发送重置密码后根本不会重定向

所以,我在app/controllers/users /下创建了一个名为passwords_controller.rb的新文件

看起来像这样

class User::PasswordsController < Devise::PasswordsController

    def create
    self.resource = resource_class.send_reset_password_instructions(resource_params)

            if successfully_sent?(resource)
            flash[:notice] = "sent password"
            else
              respond_with(resource)
            end
        end

        def new
            super
        end

        def update
            super

        end
        def edit
            super

        end
    end
Run Code Online (Sandbox Code Playgroud)

并改变了我的路线

 devise_for :users, :controllers => { :invitations => 'users/invitations', :passwords => 'users/passwords' }
Run Code Online (Sandbox Code Playgroud)

我也有devise_invite宝石..

当我点击忘记密码的链接时,我收到此错误

Started GET "/users/password/new" for 127.0.0.1 at 2012-11-16 10:21:07 +0200

ActionController::RoutingError (uninitialized constant Users::PasswordsController): …
Run Code Online (Sandbox Code Playgroud)

inheritance controller devise ruby-on-rails-3

5
推荐指数
1
解决办法
1万
查看次数

我可以将CSS过滤器应用于背景图像吗?

我想像这样在后台拍照

body{

    background-color: transparent !important;
    background-image: url("img.jpg");
    background-size: cover;
    background-position: center center;
    background-repeat: no-repeat;
    background-attachment: fixed;
    filter: blur(5px);
-webkit-filter: blur(5px);
-moz-filter: blur(5px);
-o-filter: blur(5px);
-ms-filter: blur(5px)


}
Run Code Online (Sandbox Code Playgroud)

但也有一个模糊过滤器.

然而,当我把它放在身体上时,除了背景图像之外,所有东西都会模糊.

有没有办法只在背景图像上应用模糊?(除了做Photoshop或类似的模糊.

css filter css3

5
推荐指数
1
解决办法
2万
查看次数

jQuery单击另一个div顶部的div

我有一个jQuery的问题,click当选择器是一个div在另一个顶部时,div如此处所示..

HTML

<div id="parent">
 <div id="child">
 </div>
</div>?
Run Code Online (Sandbox Code Playgroud)

CSS

#parent{
 background-color:red;
 width:100px;
 height:100px;   
 position:relative;
}


#parent:hover #child {
 display:block;

}
#child{
 background-color:yellow;  
 width:10px;
 height:10px;  
 border: 1px solid black;
 position:absolute;
 display:none;
 bottom:0;
 right:0;
}
Run Code Online (Sandbox Code Playgroud)

JS

$("#parent").bind("click", function() {
    alert('you clicked on red');
});

$("#child").bind("click", function() {
    alert('you click on yellow');
});?
Run Code Online (Sandbox Code Playgroud)

如果单击红色,#parent则会显示正确的警报.如果单击黄色#child,则会显示黄色警报和红色警报.

看到jsfiddle

有没有办法来解决这个问题?

jquery

5
推荐指数
1
解决办法
1670
查看次数

如何在Rails中使用respond_to设置自定义flash

respond_to你可以设置flash[:notice]这样的

respond_to do |format|
  format.html { redirect_to photo_path(photo), :notice => 'The photos was saved') }
  format.xml  { render :xml => photo, :status => :created}
end
Run Code Online (Sandbox Code Playgroud)

我试图设置flash [:success] :success => "yay"但它不起作用.

难道我做错了什么?

respond-to ruby-on-rails-3

5
推荐指数
2
解决办法
2781
查看次数

回形针附件文件大小

如何获取回形针附件的每种样式的文件大小?

@user.attachment_file_size 似乎不起作用

@user.attachment(:style).size
Run Code Online (Sandbox Code Playgroud)

给出与实际文件大小无关的数字

attachment filesize paperclip ruby-on-rails-3

5
推荐指数
1
解决办法
3998
查看次数

使跨度表现得像一个按钮

我有以下HTML

<div class="btns">

<div id="green">    <span class="btn btn-block btn-large btn-success disabled green_btn">Green</span>

 <div class="num">(1)</div>
</div>
<div id="red">
    <form class="button_to" >
        <div>
            <input class="btn btn-block btn-large btn-danger red_btn"
            type="submit" value="Red">
        </div>
    </form>
    <div class="num">(0)</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)

和css

.btns {
    position: relative;
}

.num {
    position: absolute;
    bottom: 0;
    width: 100%;
    text-align: center;
}

#green, #red {
    display: inline-block;
    width: 49%;
    position: relative;
}

.green_btn, .red_btn {
    margin-bottom: 4px;
}
Run Code Online (Sandbox Code Playgroud)

我无法弄清楚为什么绿色范围下的(1)在红色按钮下的行为不像(0).如果我将bottom:0;其移除,则修复绿色,但会混淆红色.

这是一个jsfiddle来说明问题http://jsfiddle.net/HajHV/

我在这里错过了什么?

html css

5
推荐指数
1
解决办法
2万
查看次数

Rails 关联中的复数名称

我有用户模型和汽车模型

我想要一个模型来保存每辆车和每个用户的设置

所以我做

class CarSettings < ActiveRecord::Base

  belongs_to :user
  belongs_to :car
end
Run Code Online (Sandbox Code Playgroud)

对于用户:

  has_many :car_settings
Run Code Online (Sandbox Code Playgroud)

对于汽车:

  has_many :car_settings
  has_many :users, :through => :car_settings
Run Code Online (Sandbox Code Playgroud)

请注意名称 CarSettings,这不是一个错误,我希望它是设置而不是设置

当我做

c=Car.first
c.users
Run Code Online (Sandbox Code Playgroud)

我明白了

NameError: uninitialized constant Car::CarSetting
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.12/lib/active_record/inheritance.rb:111:in `compute_type'
Run Code Online (Sandbox Code Playgroud)

它正在寻找单一的 car_setting 而不是 car_settings。

我怎样才能解决这个问题?

associations relationship plural model-associations ruby-on-rails-3

5
推荐指数
1
解决办法
2257
查看次数