2

我有一个使用带有订阅者模型的设计的 rails 3 应用程序。我希望订阅者使用 best_in_place gem 更新他们的帐户信息,但我似乎无法让它更新数据库。它将在屏幕上更新,但不会在数据库上更新。

该错误似乎表明订阅者存在是一件坏事,但事实并非如此,因为如果该订阅者不存在,就不可能更新它。

我想要做的就是能够允许用户从显示他们详细信息的订阅者/帐户#show 页面更新他们的信息。

我的订户/帐户控制器有这个:

    def update
      @subscriber = Subscriber.find(current_subscriber.id)
      @subscriber.update_without_password(params[:subscriber])
    end

我总是在服务器日志中得到这些结果:

Processing by Subscribers::AccountsController#update as JSON
Parameters: {"subscriber"=>{"firstname"=>"Aarof"}, "authenticity_token"=>"Sx6kEQy4NC56ovikMs/D9nVPGJt1q5jNCoFnNjFhDu8=", "id"=>"2"}
Subscriber Load (1.9ms)  SELECT `subscribers`.* FROM `subscribers` WHERE `subscribers`.`id` = 2 LIMIT 1
CACHE (0.0ms)  SELECT `subscribers`.* FROM `subscribers` WHERE `subscribers`.`id` = 2 LIMIT 1
(0.2ms)  BEGIN
Subscriber Exists (0.4ms)  SELECT 1 AS one FROM `subscribers` WHERE (`subscribers`.`email` = BINARY 'frostsquid@yahoo.com' AND `subscribers`.`id` != 2) LIMIT 1
(0.1ms)  ROLLBACK
Redirected to http://localhost:3000/subscribers/accounts/2
Completed 302 Found in 12ms (ActiveRecord: 2.6ms)

我的显示页面如下所示:

%p.subscriber-account-info
  =best_in_place @subscriber, :firstname, :path => subscribers_account_path(@subscriber)

我的订阅者路线如下所示:

       subscribers_accounts GET    /subscribers/accounts(.:format)                  subscribers/accounts#index
                            POST   /subscribers/accounts(.:format)                  subscribers/accounts#create
    new_subscribers_account GET    /subscribers/accounts/new(.:format)              subscribers/accounts#new
   edit_subscribers_account GET    /subscribers/accounts/:id/edit(.:format)         subscribers/accounts#edit
        subscribers_account GET    /subscribers/accounts/:id(.:format)              subscribers/accounts#show
                            PUT    /subscribers/accounts/:id(.:format)              subscribers/accounts#update

我刚刚检查了尝试使用控制台更新订阅者的名字,并收到了订阅者存在的相同消息,并且它回滚了事务。这是因为设计中的某些东西吗?

4

1 回答 1

2

也许有点答案,但你对 JSON 有反应吗?这里是我们项目的示例代码:

def update
    respond_to do |format|
      resource_files_service.update(@resource_file, params[:resource_file], current_user)

      format.html { }
  format.json { respond_with_bip(@resource_file) }
end
于 2012-07-30T10:24:12.567 回答