我下面這個railscast實現一個簡單的解決方案來處理靜態頁面:http://railscasts.com/episodes/117-semi-static-pages-revised?view=asciicast未定義的方法`stringify_keys'爲‘測試’:字符串
我有越來越的更新方法在我的網頁的具體問題控制器工作。
我的路線文件:
Jog::Application.routes.draw do
root :to => 'categories#index'
devise_for :categories
devise_for :users
resources :categories do
resources :gists
end
resources :sub_categories, :gists, :pages, except: "show, edit, update, destory"
get ':id', to: 'pages#show', as: :page
get ':page/edit', to: 'pages#edit', as: :edit_page
put ':page', to: 'pages#update', as: :update_page
delete ':page', to: 'pages#destroy', as: :destroy_page
end
這裏是我的模型:
class Page < ActiveRecord::Base
resourcify
attr_accessible :content, :name, :permalink
validates_uniqueness_of :permalink
def to_param
permalink
end
end
我的控制器更新方法:
def update
@page = Page.find_by_permalink!(params[:page])
respond_to do |format|
if @page.update_attributes(params[:page])
format.html { redirect_to @page, notice: 'Page was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @page.errors, status: :unprocessable_entity }
end
end
end
我的錯誤:未定義的方法`stringify_keys'爲「測試「:字符串
我研究了其他'stringify_keys'錯誤,但找不到類似的東西。謝謝你的幫助。
這不是因爲所有其他方法正在工作(我也試圖確保)。這裏是錯誤行,測試是頁面名稱:app/controllers/pages_controller.rb:72:在'block in update'中 app/controllers/pages_controller.rb:71:在'update' – Anthony
這些是被引用的行在更新方法中: respond_to do | format | if @ page.update_attributes(params [:page]) – Anthony
啊,這個鏈接怎麼樣? http://railsforum.com/viewtopic.php?id=29132所以你可以將第71行改成'@ page.update_attributes(:page => params [:page])' – jstim