小编Aja*_*jay的帖子

用于在Rails应用程序中创建全功能博客的Gem

我需要一个gem来在我的rails应用程序中创建一个Blog.我们可以编写一大堆代码,但对于这个小任务,有效的Gem更可取.请建议一个好的Gem来创建支持以下功能的博客:

- Adding static  Blog contents. 
- Feature to have image in blog
- Visitor/Viewer must be able to comment/share the blog 
 ( will be much nicer if can be commented/shared via Facebook account)
Run Code Online (Sandbox Code Playgroud)

我通过了Gems:

-  "Redcloth" (for creating static web pages quickly; quite unsure 
    will it be able to handle image & comment facility. )
-  Gem "dynarex-blog" (for creating blog, but unable to find 
   good tutorial / proper documentation for integrating it with my Application).
Run Code Online (Sandbox Code Playgroud)

gem blogs ruby-on-rails redcloth

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

Angular2 - 提供的参数与调用目标的任何签名都不匹配

import { Component, Input, OnChanges } from '@angular/core';

@Component({
  selector: 'image-display',
  templateUrl: './image-display.component.html'
})
export class ImageDisplayComponent implements OnChanges {
  @Input() image: File;
  @Input() imagePath?: string;

  private fileReader: FileReader;

  constructor() { }

  ngOnChanges() {
    if (this.image && this.fileReader) {
      this.fileReader.readAsDataURL(this.image);
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

在使用AOT进行编译时得到以下错误:

PRINHYLTPAP0592:matata ajays$ ng build --prod --aot
/myApp/src/$$_gendir/app/image-uploader/image-display/image-display.component.ngfactory.ts (61,9): 
Supplied parameters do not match any signature of call target.
Run Code Online (Sandbox Code Playgroud)

angular2-aot angular

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

如何将救援块移动到方法

我在我的一个模型中有以下方法来保存用户记录:

def save_user(params)
  begin 
    save_user_details(params)
  rescue ActiveRecord::RecordInvalid => ex  
    { success: false, errors: ex.messages }
  rescue Exception => ex
    Rails.logger.info(ex.message)
    Rails.logger.info(ex.backtrace.join(‘\n’)
    { success: false, errors: ’Some error occurred.}
  end
end
Run Code Online (Sandbox Code Playgroud)

我们可以看到rescue块很重,这种块在其他行为中也很常见.所以我考虑重构这个并将rescue块移动到一个单独的函数.我想实现这样的事情:

def save_user(params)
  begin 
    save_user_details(params) # my method to save the details 
    handle_the_exception # not sure how to implement this 
  end
  def handle_the_exception
    # How to handle here ? 
  end
Run Code Online (Sandbox Code Playgroud)

如上所述对实施的任何想法都将是一个很大的帮助.

ruby ruby-on-rails exception block

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

如何在Twitter引导程序中放置右侧固定导航栏

我想在右侧添加4个导航按钮.单击,我可以导航到同一页面中的相应div.(就像单页设计一样).

我正在添加以下代码行,以在页面右侧创建4个导航按钮.

    <div data-spy="affix" class="offset8 span1 well offset7 small">
        <ul class="nav nav-list">
            <a class=".move-1" data-target=".home-1-image"> A </a>
            <a class=".move-1" data-target=".home-2-image"> B </a>
            <a class=".move-1" data-target=".home-3-image"> C </a>
            <a class=".move-1" data-target=".home-4-image"> D </a>
        </ul>
  </div>
Run Code Online (Sandbox Code Playgroud)

但是这些代码行并没有将我的4个按钮放在最右边.检查快照. 在此输入图像描述

可以使用哪些引导类使其位于最右侧,并且应将其固定在适当位置.(响应能力应该得到很好的照顾).

css twitter-bootstrap

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

无法使用Deface覆盖现有部分

在"spree_application.html.erb"文件中,我需要覆盖现有的部分从下面的链接获取完整的代码:

https://github.com/spree/spree/blob/v2.1.2/frontend/app/views/spree/layouts/spree_application.html.erb

样品内容:

      <%= render :partial => 'spree/shared/header' %>

      <div id="wrapper" class="row" data-hook>

        <%= breadcrumbs(@taxon) %>

        <%= render :partial => 'spree/shared/sidebar' if content_for? :sidebar %>

        <div id="content" class="columns <%= !content_for?(:sidebar) ? "sixteen" : "twelve" %>" data-hook>
          <%= flash_messages %>
          <%= yield %>
        </div>

        <%= yield :templates %>

      </div>
Run Code Online (Sandbox Code Playgroud)

在这里我需要使用Deface替换以下部分:

  <%= render :partial => 'spree/shared/header' %>
Run Code Online (Sandbox Code Playgroud)

我的Deface文件:header_modification.rb:

 Deface::Override.new(:virtual_path => 'spree/layouts/spree_application',
                      :name         => 'header_modification',
                      :replace      =>    ?
                      :partial      => 'spree/shared/spree_application'
                     )
Run Code Online (Sandbox Code Playgroud)

应该写什么:替换部分/任何其他动作可以用来覆盖使用Deface的部分?

ruby-on-rails spree

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

如何从存储在 ruby​​ 哈希中的数组中删除特定值

我在我的错误列表中得到了这个:

@error_messages = {
                   :password=>["can't be blank", "Password is required."], 
                   :"addresses.firstname"=>["can't be blank","Firstname is required."],
                   :"addresses.city"=>["can't be blank", "city is required."]
                  }
Run Code Online (Sandbox Code Playgroud)

在这里,我想从此哈希中删除值“不能为空”值,以便我将获得我包含的验证错误消息。

是否可以从上面的哈希列表中删除“不能为空”值,我会得到这个结果:

       @error_messages = {
                          :password=>["Password is required."],
                          :"addresses.firstname"=>["Firstname is required."],
                          :"addresses.city"=>["city is required."]
                         }
Run Code Online (Sandbox Code Playgroud)

如何从哈希列表中删除特定值(想要删除特定值而不是完整的键值对)。

ruby arrays hashset

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

无法在spree 2.1.3中替换spree默认徽标

使用过的萤火虫和经过检查的Spree默认徽标来自 /assets/store/logo.png

检查大礼包2.1.3版本源代码,发现默认徽标来自/ logo部分.

路径:

core/app/models/spree/app_configuration.rb

preference :logo, :string, default: 'logo/spree_50.png'
Run Code Online (Sandbox Code Playgroud)

尝试使用Spree:Config选项覆盖默认徽标.

Spree::Config.set(logo: "store/logo.png")
Run Code Online (Sandbox Code Playgroud)

但它仍然重定向到旧图像(spree_50.png),我无法替换默认徽标.

spree ruby-on-rails-4

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

如何将控制器中的json响应传递给rails中的ajax调用

这是我在js文件中的ajax调用部分:

$("#sign_submit").click(function(){
            email_id = $("#user_email").val();
            password = $("#user_password").val();

            data =  {email: email_id, password: password };
            url = user/sign_in';

            $.ajax({
                url: url,
                data:  data,
                cache: false,
                type: "post",
                success: function(data){
                    console.log(data);
                }
              });
});
Run Code Online (Sandbox Code Playgroud)

这是我的控制器动作:

  def create
    @user = User.find_by_email(params['email'])
    if @user.nil?
      respond_to do |format|
        format.json {render :json => {:response => 'User is invalid'} }     #how to pass json response here. 
      end
    end

    if @user.check_valid_user?(params['password'])
      set_dashboard_location
      set_current_user(session[:customer_id])
      render js: %(window.location.href='#{session["spree_user_return_to"]}')
    else
       #redirect_to '/' and return 
       #how to psas json response here. …
Run Code Online (Sandbox Code Playgroud)

ajax jquery ruby-on-rails

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