2012-10-24 17 views
1

我不太确定如何描述这个问题,所以将尝试清楚。停止发布到外部服务寻找用户ID

我们的Rails应用程序中有一个页面,我们的客户可以更新其信用卡详细信息。表单发布到外部服务以验证详细信息。然后透明地重新导向给我们。

最初,我在自己的控制器中进行了测试(完美工作),但我刚刚在我的users_controller中移动了它。

表单帖子和重定向到一个确认操作,它会进行一些检查。当我从用户控制器内发帖时,出现以下错误:

Couldn't find User with id=k2hx5p36w3g9rxsz 

事实上,这是事务的ID。不是用户。

的URL看起来是这样的:

http://localhost:8080/settings/confirm?http_status=200&id=k2hx5p36w3g9rxsz&kind=update_payment_method&hash=9c85b12c1242cd58de27b2582c934e34a0e9455e6 

在我的控制,我有这样的:

def billing 
    @user = current_user 
    @credit_card = current_user.default_credit_card 
    @tr_data = CreditCard::TransparentRedirect.update_credit_card_data(:redirect_url => confirm_credit_card_info_url, :payment_method_token => @credit_card.token) 
    ... 
end 

def credit_card_confirm 
    @user = current_user 
    @result = CreditCard::TransparentRedirect.confirm(request.query_string) 

    if @result.success? 
    redirect_to user_billing_path, :notice => "Credit card updated" 
    else 
    render :action => "billing" 
    end 
end 

在我的路线:

match '/settings/confirm' => 'users#credit_card_confirm', :as => :confirm_credit_card_info 

我能做些什么来避免它将ID作为用户ID?

回答

1

您可能有类似于before_filtercancan的东西,它会从params中获取id并尝试加载相应的对象。这是控制器中的常见做法。

的一点是,params包含的合并:

所以GET /users/1GET /users?id=1具有相同的效果。

解决方案是了解您的代码中哪些特定的代码用于加载用户。如果它是您的代码(或以其他方式可跳过),则跳过过滤器或适用于credit_card_confirm操作的任何适当代码,如果它不是您的代码,则必须使用单独的控制器。

+0

就是这样。使用load_and_authorize_resource和skip_authorize_resource停止验证。干杯。小号 – simonmorley