Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I was following this railscast to implement a simple solution to deal with static pages: http://railscasts.com/episodes/117-semi-static-pages-revised?view=asciicast

The specific problem I'm having is getting the update method in my pages controller to work.

My routes file:

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

Here is my model:

class Page < ActiveRecord::Base
resourcify
attr_accessible :content, :name, :permalink
validates_uniqueness_of :permalink

def to_param
permalink
end
end

My controller update method:

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

My error: undefined method `stringify_keys' for "test":String

I've researched other 'stringify_keys' errors but couldn't find anything similar to this. Thanks for your help.

share|improve this question
add comment

2 Answers

In your routing file, change the value from a string to an array of symbols. I don't think it understands what methods you are trying to exclude.

resources :sub_categories, :gists, :pages, except: [:show, :edit, :update, :destroy]

If that isn't it, can you point out the line number that the error is pointing to? where the test variable is being used?

share|improve this answer
    
That wasn't it because all the other methods are working (I tried it also to make sure). Here is the error line, test is the page name: app/controllers/pages_controller.rb:72:in block in update' app/controllers/pages_controller.rb:71:in update' –  Anthony Oct 19 '12 at 23:52
    
These are the lines being referenced in the update method: respond_to do |format| if @page.update_attributes(params[:page]) –  Anthony Oct 20 '12 at 0:39
    
ah, what about something like this link? railsforum.com/viewtopic.php?id=29132 so you would change line 71 to something like @page.update_attributes(:page => params[:page]) –  jstim Oct 20 '12 at 2:04
    
I tried that but it leads to another series of errors like: unknown attribute: page –  Anthony Oct 20 '12 at 22:19
add comment

String_keys error is thrown up when the function is expecting a collection rather than a string or symbol. The :except option in the resources function above expect an array having the name of the actions in the symbol form...

Also tell me where the test variable is used and the line where the error is being raised...

share|improve this answer
    
Test is the name of the page, I find the pages by their permalink. def update @page = Page.find_by_permalink!(params[:id]) respond_to do |format| if @page.update_attributes(:id => params[:page]) –  Anthony Oct 20 '12 at 22:44
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.