小编Lau*_*ent的帖子

Rails 3 +动作邮件程序 - 无法循环发送电子邮件

用户可以创建一个对象,并且他在创建此对象时有我想要提醒的关注者.

控制器:

if @project.save
  format.html { redirect_to(@project, :notice => 'Project was successfully created.') }
  format.xml  { render :xml => @project, :status => :created, :location => @project }
  # Send a notification to project owner's followers :
  UserMailer.new_project(@project).deliver
else
  ...
Run Code Online (Sandbox Code Playgroud)

user_mailer.rb:

def new_project(project)
    @url  = "http://localhost:3000/"
    @project = project
    # For each of project owner's follower, send an email notification
    @followers = project.owner.followers.all
    @followers.each do |f|
        @u = User.find(f.follower)
        mail(   :to => @u.email,
            :from => '"Beatrix Kiddo" <beatrix@example.com>',
            :subject => "#{project.owner.name} …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails actionmailer

24
推荐指数
2
解决办法
5706
查看次数

Rails 3 - 从阵列A中删除属于阵列B的项目

我开始玩数组了,但我仍然坚持一些似乎非常简单的东西...
我试图从另一个数组中删除属于一个数组的x个元素.
我已经看了这个但是....阻止: 从数组中删除项目需要多次传递才能将它们全部删除

a = ["1","2","3","4","5","6"]
b = ["1","3"]
c = a.reject { |i| i =~ /b/ }
Run Code Online (Sandbox Code Playgroud)

好吧,我在这里有点多,谢谢!

ruby arrays ruby-on-rails-3

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

Rails - 使用params中的run_at /指定何时发布的特定方法的延迟作业

我在这里有点不知所措.
我只是试图在用户定义的时间延迟签入.我想尽量简单.
编辑:解决,见下文.

class MyController < ApplicationController

  def new_checkin
    # default venue is "SubMate"
    @venue_id = params[:venue_id] || "4c2c3acd8abca59355760120"
    @time = params[:time]
    @checkin = Delayed::Job.enqueue(self.perform_checkin, :run_at => @time.minutes.from_now)
  end

  def perform_checkin
    foursquare.checkins.add(:venueId => @venue_id, :broadcast => "private")
  end
Run Code Online (Sandbox Code Playgroud)

结果很奇怪:delayed_job是保存,执行操作(没有请求的@time延迟),我仍然收到错误:

ArgumentError in MyController#new_checkin
  Cannot enqueue items which do not respond to perform
Run Code Online (Sandbox Code Playgroud)

我错过了什么?如何在用户请求延迟的情况下执行此延迟作业?

谢谢!

更新
感谢下面的@Roman,不知道你可以传递参数来延迟:

def new_checkin
  @venue_id = params[:venue_id]
  @time = params[:time]
  @checkin = self.perform_checkin
end

def perform_checkin
  foursquare.checkins.delay({:run_at => @time.minutes.from_now}).add(:venueId => @venue_id, :broadcast => "private")
end
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails delayed-job

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

Omniauth - Origin是零

我正在使用推特的宝石.在回调时,检查用户是否存在并创建他或将他发送回主页.
我可能做错了,但在我的回调代码中,request.env ['omniauth.origin']是零.

我的代码非常简单:
whatever.html.erb

<%= link_to image_tag("twitter-connect.png"), "/auth/twitter" %>
Run Code Online (Sandbox Code Playgroud)

的routes.rb

match "/auth/:provider/callback" => "sessions#create"
Run Code Online (Sandbox Code Playgroud)

sessions_controller.rb

def create
    auth = request.env["omniauth.auth"]
    user = User.find_by_provider_and_uid(auth["provider"], auth["uid"]) || User.create_with_omniauth(auth)
    if !user.email
        redirect_to confirm_path, :notice => "Add your email!"
    else
        redirect_to request.env['omniauth.origin'] || root_url, :notice => "Signed in!"
    end
end
Run Code Online (Sandbox Code Playgroud)

如果我在回调后立即提出request.env ['omniauth.origin'],我会得到一个nil对象.

谢谢你的帮助!

ruby-on-rails omniauth

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