小编Sur*_*oza的帖子

在5秒Swift之后解散UIAlertView

我创建了一个包含UIActivityIndi​​cator的UIAlertView.一切都很好,但我也希望UIAlertView在5秒后消失.

如何在5秒后解除我的UIAlertView?

 var alert: UIAlertView = UIAlertView(title: "Loading", message: "Please wait...", delegate: nil, cancelButtonTitle: "Cancel");

 var loadingIndicator: UIActivityIndicatorView = UIActivityIndicatorView(frame: CGRectMake(50, 10, 37, 37)) as UIActivityIndicatorView
 loadingIndicator.center = self.view.center;
 loadingIndicator.hidesWhenStopped = true
 loadingIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.Gray
 loadingIndicator.startAnimating();

 alert.setValue(loadingIndicator, forKey: "accessoryView")
 loadingIndicator.startAnimating()

 alert.show()
Run Code Online (Sandbox Code Playgroud)

delay uialertview uiactivityindicatorview ios swift

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

更改信用卡信息(条纹)

我终于想出了如何使用本教程实现Stripes Monthly Billing. http://railscasts.com/episodes/288-billing-with-stripe

到目前为止,用户可以使用Stripe创建和删除其订阅.

但是,用户如何在创建订阅后更改其信用卡信息

这是我的评论和问题代码.请帮助新的rails.:)

CONTROLLER

class SubscriptionsController < ApplicationController

  def new
    plan = Plan.find(params[:plan_id])
    @subscription = plan.subscriptions.build
    @subscription.user_id = current_user.id
  end

  def create
    @subscription = Subscription.new(params[:subscription])
    if @subscription.save_with_payment
      redirect_to @subscription, :notice => "Thank you for subscribing!"
    else
      render :new
    end
  end

  def update
    @subscription = current_user.subscription
     if @subscription.save
      redirect_to edit_subscription_path, :success => 'Updated Card.' 
    else
      flash.alert = 'Unable to update card.'
      render :edit 
    end
  end

end
Run Code Online (Sandbox Code Playgroud)

楷模

class Subscription < ActiveRecord::Base
  attr_accessible :plan_id, :user_id, :email, :stripe_customer_token, :last_4_digits, …
Run Code Online (Sandbox Code Playgroud)

ruby ruby-on-rails subscription stripe-payments

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

如何上传多页PDF并使用Paperclip将其转换为JPEG?

有谁知道如何使用Paperclip上传多页pdf并将每个页面转换为Jpeg?

到目前为止,每次上传PDF时,它只允许我将PDF的第一页看作JPEG.但我希望能够将PDF中的每个页面上传并转换为JPEG.

是否有任何宝石或插件可以帮助我上传10-pg PDF并在数据库中转换/存储为10个JPEG文件?

我看过docsplit-images gem,但我不确定这是解决方案的最佳解决方案还是它的工作原理.

Post.rb

class Post < ActiveRecord::Base
  belongs_to :Blogs

  attr_accessible :content, :title, :pdf

  has_attached_file :pdf,
                    :url  => "/assets/products/:id/:style/:basename.:extension",
                    :path => ":rails_root/public/assets/products/:id/:style/:basename.:extension"

  validates_attachment_content_type :pdf,
      :content_type => [ 'application/pdf' ],
      :message => "only pdf files are allowed"
end
Run Code Online (Sandbox Code Playgroud)

_form.html.erb

<%= form_for ([@post]), :html => { :multipart => true } do |f| %>

    <%= f.file_field :pdf %>

<% end %>
Run Code Online (Sandbox Code Playgroud)

show.html.erb

  <%= image_tag @post.pdf.url(:original) %>
Run Code Online (Sandbox Code Playgroud)

pdf jpeg ruby-on-rails paperclip docsplit

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

如何在公共活动中设置收件人ID

我正在浏览Public Activity Gem Railscast Vid.(http://railscasts.com/episodes/406-public-activity)

我当前的数据库查找/存储除recipient_id之外的所有内容....它显示为nil

#<PublicActivity::Activity id: 108, trackable_id: 133, trackable_type: "Relationship",
owner_id: 1, owner_type: "User", key: "relationship.create", parameters: {}, 
recipient_id: nil, recipient_type: nil, created_at: "2013-06-16 07:37:28", 
updated_at: "2013-06-16 07:37:28">
Run Code Online (Sandbox Code Playgroud)

我希望recipient_id成为正在执行操作的用户....

防爆.

如果我喜欢Tom's Post .....我希望Tom的ID成为recipient_id我将成为owner_id.

我目前设置了一个收件人ID ....使用我的喜欢控制器中的代码....但它只将收件人ID设置为当前用户....这不是我想要的:(

喜欢控制器

class Like < ActiveRecord::Base
  include PublicActivity::Model
  tracked except: :destroy, owner: ->(controller, model) { controller && controller.current_user }

  **tracked except: :destroy, recipient: ->(controller, model) { controller && controller.current_user }**

  attr_accessible :dailypost_id, :user_id

  belongs_to :user
  belongs_to :dailypost


  default_scope order: 'likes.created_at …
Run Code Online (Sandbox Code Playgroud)

ruby gem ruby-on-rails railscasts ruby-on-rails-3

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

您的 Gemfile 多次列出该 gem。可能会导致错误

当我运行捆绑安装时,我当前收到以下消息

Your Gemfile lists the gem sqlite3 (= 1.3.5) more than once.
You should probably keep only one of them.
While it's not a problem now, it could cause errors if you change the version of just one of them later.

Your Gemfile lists the gem rspec-rails (= 2.10.0) more than once.
You should probably keep only one of them.
While it's not a problem now, it could cause errors if you change the version of just one of them …
Run Code Online (Sandbox Code Playgroud)

ruby sqlite postgresql ruby-on-rails heroku

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

Grouped Collection选择按字母顺序排列的Rails

我终于想出了如何使用本教程实现动态选择菜单.

一切正常,但是如何按名称组织下拉列表中的城市....

以下是我写的所有代码.(如果您需要任何进一步的信息,请告诉我)

新的铁路请帮助:)

VIEWS

<%= simple_form_for ([@book, @rating]) do |f| %>

  <div class="field">
    <%= f.collection_select :state_id, State.order(:name),  :id, :name, {:include_blank=> "Select a State"}, {:class=>'dropdown'} %>
  </div>


  ### I would like the order of the cities displayed in the drop down to be alphabetized 
  <div class="field">
    <%= f.grouped_collection_select :city_id, State.order(:name), :cities, :name, :id, :name, {:include_blank=> "Select a City"}, {:class=>'dropdown'} %>
  </div>        

<% end %>
Run Code Online (Sandbox Code Playgroud)

ruby ruby-on-rails simple-form grouped-collection-select

4
推荐指数
2
解决办法
3712
查看次数

更新Stripe的客户信用卡信息

我终于想出了如何使用本教程实现Stripes Monthly Billing .

到目前为止,用户可以使用Stripe创建和删除其订阅.但我无法调用API中的哈希值以让用户更改其信用卡信息.

问题:如何调用/传递文档中的子参数以使用我创建的方法更新信用卡字段update_card

这是我的评论代码:

CONTROLLER

class SubscriptionsController < ApplicationController

  def update
    @subscription = current_user.subscription

    ### I use the method update_card to update the customer's card
    @subscription.update_card  

     if @subscription.update_card
      redirect_to edit_subscription_path, :success => 'Updated Card.' 
    else
      flash.alert = 'Unable to update card.'
      render :edit 
    end
  end

end
Run Code Online (Sandbox Code Playgroud)

楷模

class Subscription < ActiveRecord::Base
  attr_accessible :plan_id, :user_id, :email, :stripe_customer_token, :last_4_digits,
              :card_token, :card_name, :exp_month, :exp_year, :stripe_card_token

  attr_accessor :stripe_card_token

  belongs_to :plan
  belongs_to :user

  ### How can this work …
Run Code Online (Sandbox Code Playgroud)

ruby hash ruby-on-rails subscription stripe-payments

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

PostgreSQL - group by子句或用于聚合函数(错误)

我正在关注这个导演视频:http: //railscasts.com/episodes/382-tagging.在Postgres上使用我的Rails 3.2应用程序进行标记.

除标签云功能外,一切都很完美.出于某种原因,云功能在使用Heroku的Production中不起作用.

我收到这个错误

ActionView::Template::Error (PGError: ERROR:  column "tags.id" must appear 

in the GROUP BY clause or be used in an aggregate function
Run Code Online (Sandbox Code Playgroud)

我知道错误来自在Heroku中使用Postgres,但我不知道如何解决它.我在下面发布了我的代码.

Rails新手....请帮忙:)

VIEWS

##The error occurs here..

  <div id="tag_cloud">
    <% tag_cloud Dailypost.tag_counts, %w[s m l] do |tag, css_class| %>
      <%= link_to tag.name, tag_path(tag.name), class: css_class %>
    <% end %>
  </div>
Run Code Online (Sandbox Code Playgroud)

楷模

class Tag < ActiveRecord::Base
  attr_accessible :name
  has_many :taggings
  has_many :dailyposts, through: :taggings
end

class Tagging < ActiveRecord::Base
  attr_accessible :dailypost_id, :tag_id

  belongs_to :tag …
Run Code Online (Sandbox Code Playgroud)

ruby postgresql tagging ruby-on-rails heroku

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

链接到活动管理中的自定义多态关联操作

我正在与 Active Admin 合作。目前,我有一个索引页面,允许我查看用户标记的所有资源。鉴于存在各种类型的资源,我的 Flagg 类和各种资源表之间存在多态关系。

在我的索引页面中,在 Active Admin 上,我希望能够链接到属于特定资源类型的相应显示页面。

我已经让我所有的代码都能工作了,但我不喜欢我想出的解决方案。

我如何改进我当前的解决方案,这样我就不必写一个尴尬的条件?

楷模

class Flag < ActiveRecord::Base
  #create relationships with user and flag model
  belongs_to :flaggable, polymorphic: true
end

class MilitaryResource < ActiveRecord::Base
  has_many :flags, as: :flaggable, :dependent => :destroy  
end

class DistrictResource < ActiveRecord::Base
  has_many :flags, as: :flaggable, :dependent => :destroy  
end

class SchoolResource < ActiveRecord::Base
  has_many :flags, as: :flaggable, :dependent => :destroy  
end
Run Code Online (Sandbox Code Playgroud)

活动管理员

ActiveAdmin.register Flag do

  #parameters permitted to create military resources
  permit_params :id, :user_id, :flaggable_id, :flaggable_type, …
Run Code Online (Sandbox Code Playgroud)

ruby polymorphism ruby-on-rails polymorphic-associations activeadmin

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