Undefined Method Model Path, Form_for not saving, Posted Correctly, Rails Framework -


sorry new rails

right trying build small application https://pinboard.in, trying summer internship them.

here bookmark model

class bookmark < activerecord::base   attr_accessible :url, :title, :description, :counter    belongs_to :user     #validates url has https:// or http://   validates :url, :format => { :with => /(^$)|(^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-  9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?$)/ix,   :message => "invalid url" } end 

here bookmark controller

class bookmarkscontroller < applicationcontroller     def add_bookmark         @bookmark = bookmark.new           respond_to |format|             format.html          end      end       def draw_recent         @bookmarks = bookmark.all     end  end 

here form

<%= form_for :bookmark |f| %>     url: <%= f.text_field :url %><br/>     title: <%= f.text_field :title %><br/>     description: <%= f.text_field :description %><br/>     <%= f.submit "submit" %> <% end %> 

everything rendered correctly , when put in information , submit add

here output

started post "/add" 127.0.0.1 @ 2013-05-09 09:55:58 -0400 processing bookmarkscontroller#add_bookmark html   parameters: {"utf8"=>"✓",    "authenticity_token"=>"zcxa226povyu5akqamvvfkz5upq4gfggptwrswtqzyk=", "bookmark"=>  {"url"=>"http://litmus.com", "title"=>"email marketing ", "description"=>"email marketing "},  "commit"=>"submit"} rendered bookmarks/_form.html.erb (1.9ms) rendered bookmarks/add_bookmark.html.erb within layouts/application (3.3ms) completed 200 ok in 96ms (views: 95.4ms | activerecord: 0.0ms) 

i have 2 thoughts in head, form posting correctly somehow not saving db, need save method in controller?

when try @bookmark instead of :bookmark app throws me error saying wrong bookmarks.path

undefined method `bookmarks_path 

i understand former working instance @bookmark in controller , latter wrapping around model....

can enlighten me? feel trivial guys... :)

should form_for @bookmark |f|. getting undefined method error because have not defined routes in config/routes.rb, add there:

resources :bookmarks 

that add restful resources following crud convention, should change name of controller methods work out-of-the-box. need @ least 3 methods doing right now:

in app/controllers/bookmarks_controller.rb:

first 1 render form @ /bookmarks/new

def new   @bookmark = bookmark.new end 

second 1 process form submission (no action needed apart following naming convention)

def create   @bookmark = bookmark.new(params[:bookmark])   @bookmark.save end 

third 1 show bookmarks in current 'draw_recent'

def index   @bookmark = bookmark.all end 

afterwards can go on validating data, etc basic flow should that.

it better start conventions go later on change method standard names when have more confidence.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -