【问题标题】:Rails 3 using devise and best_in_place gem, will not update subscriber modelRails 3 使用 devise 和 best_in_place gem,不会更新订阅者模型
【发布时间】:2012-07-05 23:14:22
【问题描述】:

我有一个使用带有订阅者模型的设计的 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

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

【问题讨论】:

    标签: ruby-on-rails-3 devise best-in-place


    【解决方案1】:

    也许有一点答案,但你对 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
    

    【讨论】:

    • 我没有尝试过,老实说,我不确定我需要改变什么来试一试。今晚我会看看它。
    猜你喜欢
    • 1970-01-01
    • 2014-06-23
    • 1970-01-01
    • 1970-01-01
    • 2023-03-13
    • 2019-11-21
    • 2011-09-30
    • 1970-01-01
    • 2017-05-04
    相关资源
    最近更新 更多