在我的控制器中,我有以下代码......
response = HTTParty.get('https://graph.facebook.com/zuck')
logger.debug(response.body.id)
Run Code Online (Sandbox Code Playgroud)
我得到一个NoMethodError/undefined方法`id'
如果我做...
logger.debug(response.body)
Run Code Online (Sandbox Code Playgroud)
它按原样输出......
{"id":"4","name":"Mark Zuckerberg","first_name":"Mark","last_name":"Zuckerberg","link":"http:\/\/www.facebook.com\/zuck","username":"zuck","gender":"male","locale":"en_US"}
Run Code Online (Sandbox Code Playgroud)
人们会认为这是response.body.id,但显然这不起作用.提前致谢!
我查看了有关错误的Stripe文档,但仍然在处理/重定向这些错误时遇到一些问题.基本上无论发生什么,我都希望他们回到edit动作(通过edit_profile_path)并向他们显示一条消息(无论是否成功).
我有一个关于editPOST update操作的动作的表单.这与有效的信用卡正常工作(费用在Stripe仪表板中).我正在使用Stripe.js.
class ExtrasController < ApplicationController
def edit
@extras = current_user.extras
end
def update
Stripe.api_key = "hidden"
token = params[:stripeToken]
begin
charge = Stripe::Charge.create(
:amount => 5000, # amount in cents
:currency => "usd",
:card => token,
:description => current_user.email
)
rescue Stripe::CardError => e
# redirect_to edit_extras_path, notice: e.message
# What I'm trying to do, but obviously results in AbstractController::DoubleRenderError
rescue => e
# Something else happened, …Run Code Online (Sandbox Code Playgroud) ruby error-handling ruby-on-rails ruby-on-rails-3 stripe-payments
我有一个模型Listing是belongs_to :user.或者,User has_many :listings.每个列表都有一个分类字段(狗,猫等).它User还有一个名为的布尔字段is_premium.
以下是我如何验证类别......
validates_format_of :category,
:with => /(dogs|cats|birds|tigers|lions|rhinos)/,
:message => 'is incorrect'
Run Code Online (Sandbox Code Playgroud)
假设我只想让高级用户能够添加老虎,狮子和犀牛.我该怎么做?用before_save方法做它最好吗?
before_save :premium_check
def premium_check
# Some type of logic here to see if category is tiger, lion, or rhino.
# If it is, then check if the user is premium. If it's not, it doesn't matter.
# If user isn't premium then add …Run Code Online (Sandbox Code Playgroud) 我试图用Ruby on Rails,CarrierWave和RMagick制作一个固定的方形图像裁剪.
我试过以下两个都没有运气......
version :thumb do
process :resize_to_fit => [200, 200]
end
Run Code Online (Sandbox Code Playgroud)
和
version :thumb do
process :resize_to_limit => [200, 200]
end
Run Code Online (Sandbox Code Playgroud)
resize_to_limit显然调整图像大小以适应指定的尺寸,同时保留原始高宽比.所以这不对,但resize_to_fit也没有做到.我期待在所有可用的实例方法的这里.
我希望能够上传任何宽高比和尺寸的图片,它将以200x200的形式出现.