HELP! I’m a relatively new rails user and I’m stuck. I’m trying to
build a relatively simple blog and I decided that I liked the way
named routes look in the code. So I added
map.resources :posts
to my routes.db file. I then went through and updated my controller to
take advantage of the named routes that were generated. I also updated
all of my views and everything was working nicely. Except when I try
to edit an existing post. For some reason it just doesn’t want to do
anything. Below are the relevant (I think) parts of the
PostsController:
class PostsController < ApplicationController
layout “blog”
before_filter :login_required, :except => [:index, :show]
before_filter :find_post, :except => [:index, :new, :create]
def edit
end
def update
if @post.update_attributes(params[:post])
flash[:notice] = “Post Updated”
redirect_to post_url(@post)
else
render edit_post_url
end
end
protected
def find_post
@post = Post.find(params[:id])
end
end
Here is edit.hrtml
New Post
<% form_for(:post, @post, :url => post_url(@post), :html => {:method => 'put'}) do |f| %> <%= render :partial => "form", :object => f %> <% end %>And the form partial…
Title
<%= form.text_field :title %>
Permalink
<%= form.text_field :permalink %>
Abstract
<%= form.text_area :abstract %>
Body
<%= form.text_area :body %>
<%= submit_tag %>
Have I done something stupid? I get the feeling I probably have and
it’s making the edits not work.