小编vla*_*iov的帖子

将选择形式的选项与布尔值匹配

我有以下代码

%br
= f.label :active, 'Status'
= f.select :active, ['Active','Inactive']
Run Code Online (Sandbox Code Playgroud)

符号:active是布尔类型var.如何为数据库添加匹配Active => 1/True和Inactive => 0/False.

对不起新手问题,但我无法弄清楚.

haml ruby-on-rails

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

Rails 4和Turbolinks - Meta标签不变

我有一个启用了turbo-links的Rails 4应用程序,但是在更改页面时我无法刷新元标记(不是完全刷新).我读到在加载turbo-links的javascript之前需要包含元标记,但它没有任何效果.完全刷新可以完成工作,但不幸的是,这不是我搜索的内容.

布局/ application.html.haml

%html
  %head
    %title= "Title"
    - if content_for?(:meta_description)
      %meta{content: (yield :meta_description), name: "description"}/
      %meta{content: (yield :meta_keywords), name: "keywords"}/
    = stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true 
    = javascript_include_tag "application", "data-turbolinks-track" => true

    = csrf_meta_tags
  %body{class: params[:controller].gsub("/", "-"), id: 'top'}
    = render "shared/header"
    .body-content
      = render "shared/flash"
      = yield
    = render "shared/footer"
    = render "shared/analytics"
Run Code Online (Sandbox Code Playgroud)

助手/ application_helper.rb

def meta_tag(标题,描述)

content_for :meta_keywords do
  title
end

content_for :meta_description do
  description
end   
Run Code Online (Sandbox Code Playgroud)

结束

这就是我称之为的方式

= meta_tag('here s my title', 'and the …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails turbolinks ruby-on-rails-4

12
推荐指数
2
解决办法
5561
查看次数

rescue_from :: AbstractController :: ActionNotFound无效

我有以下代码:

unless Rails.application.config.consider_all_requests_local
  rescue_from Exception, with: :render_exception
  rescue_from ActiveRecord::RecordNotFound, with: :render_exception
  rescue_from ActionController::UnknownController, with: :render_exception
  rescue_from ::AbstractController::ActionNotFound, with: :render_exception
  rescue_from ActiveRecord::ActiveRecordError, with: :render_exception
  rescue_from NoMethodError, with: :render_exception
end
Run Code Online (Sandbox Code Playgroud)

它们都完美无缺,除了:: AbstractController :: ActionNotFound

我也试过了

AbstractController::ActionNotFound
ActionController::UnknownAction
Run Code Online (Sandbox Code Playgroud)

错误:

   AbstractController::ActionNotFound (The action 'show' could not be found for ProductsController):
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails exception actioncontroller ruby-on-rails-3.2

9
推荐指数
1
解决办法
3964
查看次数

使用sublime文本2的缩进问题

我有以下问题.

我使用ubuntu 12.04和sublime-text-2或gedit.

有时我在haml/ruby​​文件中复制/粘贴一些东西,我在2个空格处缩进它,但是当我将它推到github时,缩进是完全错误的,而不仅仅是我复制/粘贴的部分.在我的编辑看起来不错.

如果我用LibreOffice/LeafPad打开文件,那么识别就像在github上一样,但我想让它在ST2上工作.

有什么建议?

github indentation sublimetext

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

未初始化的常量AssetSync

我使用gem asset_sync和aws来预编译我的资产.rake资产:预编译工作正常.我将我的应用程序推送到heroku之后

heroku run rake db:migrate
Run Code Online (Sandbox Code Playgroud)

我收到以下错误

"未初始化的常量AssetSync"

初始化/ asset_sync.rb

AssetSync.configure do |config|
  config.fog_provider = 'AWS'
  config.aws_access_key_id = "..."
  config.aws_secret_access_key = "..."
  config.fog_directory = Rails.env + "-..."
  config.fog_region = 'eu-west-1'
end
Run Code Online (Sandbox Code Playgroud)

配置/ production.rb

config.action_controller.asset_host = "//#{ENV['FOG_DIRECTORY']}.s3.amazonaws.com"
config.assets.enabled = true 
Run Code Online (Sandbox Code Playgroud)

运行rake资产后:第一次预编译,我的所有应用程序/资产/图像都被移动到公共/资产.我已经从github删除了它们并将public/assets/*添加到.gitignore.这可能是问题吗?

编辑:当运行git push heroku master时,看起来它们是预编译的

   Preparing app for Rails asset pipeline
   Running: rake assets:precompile
   AssetSync: using /tmp/build_2ltvklj0gaxjp/config/initializers/asset_sync.rb
   AssetSync: using /tmp/build_2ltvklj0gaxjp/config/initializers/asset_sync.rb
   AssetSync: Syncing.
   Using: Directory Search of /tmp/build_2ltvklj0gaxjp/public/assets
   Uploading: assets/application-7e17d9f0ed9cb7ea50b750e2bfc7e28c.css.gz
   Uploading: assets/application-7e17d9f0ed9cb7ea50b750e2bfc7e28c.css
   AssetSync: Done.
   Asset precompilation completed (58.04s)
Run Code Online (Sandbox Code Playgroud)

assets ruby-on-rails heroku amazon-web-services

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

按文件中的列批量排序

我想知道是否有可能按列对文本文件进行排序.例如

我有这样aux1.txt的行

Name SecondName Grade
Run Code Online (Sandbox Code Playgroud)

在shell中,我可以做到这一点

sort -r -k 3 aux1  
Run Code Online (Sandbox Code Playgroud)

它按第3列(等级)对文件进行排序.

批量生产

sort /+3 < aux1.txt
Run Code Online (Sandbox Code Playgroud)

在第3个字母后对文件进行排序.

我阅读了批处理的分类手册但没有结果.

sorting file batch-file

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

C++动态分配程序崩溃

我有一个非常简单的代码片段,包含2个结构和一个动态分配.程序在"nume"初始化时崩溃.

typedef struct{
    int key;
    string name;
} TElement;

typedef struct nod {
   int cheie;
   string nume;
   struct nod *stg, *dr;
} NOD;
Run Code Online (Sandbox Code Playgroud)

当我尝试这样做

void ABC::inserare_element(TElement e){
    NOD *p, *q;
    int n;
    /* construction nod p*/
    n=sizeof (NOD);
    p=(NOD*)malloc(n);
    p->cheie = e.key;
    p->nume = e.name; // on this line the program crashes
Run Code Online (Sandbox Code Playgroud)

谢谢

c++ malloc

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

如何识别mandrill webhook

我有一个Rails 4应用程序,它使用Mandrill发送电子邮件.我正在尝试检测邮件被打开或弹回的天气,所以我正在使用webhooks.我成功收到了webhooks,但我无法分辨哪些人从我的数据库中识别出特定的电子邮件.

我试过用这个

  def send_message(email)

    mail( from: ...,
          to: ...,
          subject: ...)

    headers["X-MC-AutoHtml"] = "true"
    headers["X-MC-Track"] = "opens"
    headers['X-MC-MergeVars'] = { "id" => some_id }.to_json
  end
Run Code Online (Sandbox Code Playgroud)

但是我不确定我是否应该收回X-MC-MergeVars(这是我从文档中理解的)

不幸的是,它没有用.

您有任何想法或替代解决方案吗?谢谢

ruby-on-rails ruby-on-rails-4 mandrill

0
推荐指数
1
解决办法
1252
查看次数