Hi- I am two weeks new to Ruby on Rails and I am working through the SitePoint book. Specifically Chapter 7. I am trying to do the permalink example for a story posting in their example, but I am getting an undefined method error. I have checked all the textmate files, and they match. And I have gone into the ruby console to pull the story up, find the name, but when i write: s.update_attribute :permalink, ''my-shiny-weblog''. I get a the following:>> s.update_attribute :permalink, ''my-shiny-weblog''NoMethodError: undefined method `permalink='' for #<Story:0x328d3c4> from /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/ active_record/base.rb:1858:in `method_missing'' from /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/ active_record/validations.rb:772:in `send'' from /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/ active_record/validations.rb:772:in `update_attribute'' from (irb):25>>========= When I run a full trace on http://localhost:3000/story/show/my-shiny-weblog, I get this: NoMethodError in StoryController#show undefined method `find_by_permalink'' for Story:Class RAILS_ROOT: script/../config/.. Application Trace | Framework Trace | Full Trace /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/ active_record/base.rb:1197:in `method_missing'' app/controllers/story_controller.rb:15:in `show'' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/ action_controller/base.rb:1095:in `send'' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/ action_controller/base.rb:1095:in `perform_action_without_filters'' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/ action_controller/filters.rb:632:in `call_filter'' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/ action_controller/filters.rb:619:in `perform_action_without_benchmark'' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/ action_controller/benchmarking.rb:66:in `perform_action_without_rescue'' /usr/local/lib/ruby/1.8/benchmark.rb:293:in `measure'' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/ action_controller/benchmarking.rb:66:in `perform_action_without_rescue'' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/ action_controller/rescue.rb:83:in `perform_action'' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/ action_controller/base.rb:430:in `send'' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/ action_controller/base.rb:430:in `process_without_filters'' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/ action_controller/filters.rb:624:in `process_without_session_management_support'' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/ action_controller/session_management.rb:114:in `process'' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/ action_controller/base.rb:330:in `process'' /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.2/lib/dispatcher.rb:41:in `dispatch'' /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.2/lib/webrick_server.rb: 113:in `handle_dispatch'' /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.2/lib/webrick_server.rb: 79:in `service'' /usr/local/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'' /usr/local/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'' /usr/local/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'' /usr/local/lib/ruby/1.8/webrick/server.rb:162:in `start'' /usr/local/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'' /usr/local/lib/ruby/1.8/webrick/server.rb:95:in `start'' /usr/local/lib/ruby/1.8/webrick/server.rb:92:in `each'' /usr/local/lib/ruby/1.8/webrick/server.rb:92:in `start'' /usr/local/lib/ruby/1.8/webrick/server.rb:23:in `start'' /usr/local/lib/ruby/1.8/webrick/server.rb:82:in `start'' /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.2/lib/webrick_server.rb: 63:in `dispatch'' /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.2/lib/commands/servers/ webrick.rb:59 /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'' /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'' /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.1/lib/ active_support/dependencies.rb:495:in `require'' /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.1/lib/ active_support/dependencies.rb:342:in `new_constants_in'' /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.1/lib/ active_support/dependencies.rb:495:in `require'' /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.2/lib/commands/server.rb: 39 /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'' /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'' script/server:3 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 4/10/07, Zak <zacharykidd-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hi- > > I am two weeks new to Ruby on Rails and I am working through the > SitePoint book. Specifically Chapter 7. I am trying to do the > permalink example for a story posting in their example, but I am > getting an undefined method error. I have checked all the textmate > files, and they match. And I have gone into the ruby console to pull > the story up, find the name, but when i write: > s.update_attribute :permalink, ''my-shiny-weblog''. I get a the > following: > > >> s.update_attribute :permalink, ''my-shiny-weblog'' > NoMethodError: undefined method `permalink='' for #<Story:0x328d3c4> > from /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/ > active_record/base.rb:1858:in `method_missing'' > from /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/ > active_record/validations.rb:772:in `send'' > from /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/ > active_record/validations.rb:772:in `update_attribute'' > from (irb):25 > >> > > =========> > When I run a full trace on http://localhost:3000/story/show/my-shiny-weblog, > I get this: > > NoMethodError in StoryController#show > > undefined method `find_by_permalink'' for Story:Class > RAILS_ROOT: script/../config/..First step in debugging this is to look at the error message. Your controller called Story.find_by_permalink, and it blew up. Normally, you''d just realize you either misspelled the method name, or are calling it on the wrong object. Or, maybe you got drunk and deleted it from your class :) However, ActiveRecord has "Dynamic attribute-based finders" (read about them at http://rails.rubyonrails.org/classes/ActiveRecord/Base.html). Basically, you can call Story.find_by_permalink as a shortcut for Story.find(:first, :conditions => {:permalink => ''foo''}). So, if THIS is failing, it probably means you have no permalink attribute in the model''s database table. Check and make sure it exists, you''re accessing the right DB, migrations have been run, etc etc. The first update_attribute error supports this assumption as well. -- Rick Olson http://lighthouseapp.com http://weblog.techno-weenie.net http://mephistoblog.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thnx. If my db only has the columns (schema_info, stories, and votes) should I add a column called "permalink"? Or should the column be another name? -Zak On Apr 10, 9:51 am, "Rick Olson" <technowee...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 4/10/07, Zak <zacharyk...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > Hi- > > > I am two weeks new to Ruby on Rails and I am working through the > > SitePoint book. Specifically Chapter 7. I am trying to do the > > permalink example for a story posting in their example, but I am > > getting an undefined method error. I have checked all the textmate > > files, and they match. And I have gone into the ruby console to pull > > the story up, find the name, but when i write: > > s.update_attribute :permalink, ''my-shiny-weblog''. I get a the > > following: > > > >> s.update_attribute :permalink, ''my-shiny-weblog'' > > NoMethodError: undefined method `permalink='' for #<Story:0x328d3c4> > > from /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/ > > active_record/base.rb:1858:in `method_missing'' > > from /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/ > > active_record/validations.rb:772:in `send'' > > from /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/ > > active_record/validations.rb:772:in `update_attribute'' > > from (irb):25 > > > =========> > > When I run a full trace onhttp://localhost:3000/story/show/my-shiny-weblog, > > I get this: > > > NoMethodError in StoryController#show > > > undefined method `find_by_permalink'' for Story:Class > > RAILS_ROOT: script/../config/.. > > First step in debugging this is to look at the error message. Your > controller called Story.find_by_permalink, and it blew up. Normally, > you''d just realize you either misspelled the method name, or are > calling it on the wrong object. Or, maybe you got drunk and deleted > it from your class :) > > However, ActiveRecord has "Dynamic attribute-based finders" (read > about them athttp://rails.rubyonrails.org/classes/ActiveRecord/Base.html). > Basically, you can call Story.find_by_permalink as a shortcut for > Story.find(:first, :conditions => {:permalink => ''foo''}). So, if THIS > is failing, it probably means you have no permalink attribute in the > model''s database table. Check and make sure it exists, you''re > accessing the right DB, migrations have been run, etc etc. > > The first update_attribute error supports this assumption as well. > > -- > Rick Olsonhttp://lighthouseapp.comhttp://weblog.techno-weenie.nethttp://mephistoblog.com--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---