我嘗試通過表單更新我的設置,但更新函數在我提交時未被調用。我在提交時重定向到edit_settings_path,並且根據服務器日誌更新未被調用。爲什麼?rails form更新方法不叫
<%= form_tag settings_path, :method => :put do %>
<p>
<%= label_tag :"settings[:default_email]", "System Administrator" %>
<%= text_field_tag :"settings[:default_email]", Settings['default_email'] %>
</p>
<span class="submit"><%= submit_tag "Save settings" %></span>
<% end %>
控制器
class SettingsController < ApplicationController
def update
params[:settings].each do |name, value|
Settings[name] = value
end
redirect_to edit_settings_path, :notice => "Settings have been saved." }
end
end
** **更新更新 現在被稱爲正確(編輯控制器)。服務器日誌確認Settings Load (0.2ms) SELECT "settings".* FROM "settings" WHERE "settings"."thing_type" IS NULL AND "settings"."thing_id" IS NULL AND "settings"."var" = ':default_email' LIMIT 1 UPDATE "settings" SET "value" = '--- 1111aaa2222...', "updated_at" = '2011-12-18 21:03:21.782075' WHERE "settings"."id" = 2
但它不保存到Db並且不知道爲什麼。我正在使用Rails-settings gem'git://github.com/100hz/rails-settings.git' 不知道在哪裏檢查,因爲它說它更新記錄,但事實上沒有。
你在路由器中相應設置的路線? – clyfe 2011-12-18 12:02:18
是的,我有'資源:設置'。現在它根據服務器日誌'設置加載(0.2ms)SELECT「設置」更新。*從「設置」WHERE「設置」。「thing_type」IS NULL和「settings」。「thing_id」IS NULL和「設置」。 var「=':default_email'LIMIT 1 (0.3ms)UPDATE」settings「SET」value「='--- 1111aaa2222 ...',」updated_at「='2011-12-18 21:03:21.782075'WHERE 「設置」。「id」= 2'但它不保存到Db – Gaelle 2011-12-18 21:05:48
你必須打電話保存自己 – 2011-12-19 03:47:42