diff --git a/app/controllers/posts.rb b/app/controllers/posts.rb index 1d72e62..1218ba7 100644 --- a/app/controllers/posts.rb +++ b/app/controllers/posts.rb @@ -45,7 +45,7 @@ def update @post = Post.find_by_id(params[:id]) raise NotFound unless @post if @post.update_attributes(params[:post]) - redirect url(:post, @post) + redirect url(:forum_topic, @topic) else raise BadRequest end diff --git a/app/helpers/global_helpers.rb b/app/helpers/global_helpers.rb index d4d691c..dc36ba0 100644 --- a/app/helpers/global_helpers.rb +++ b/app/helpers/global_helpers.rb @@ -1,5 +1,8 @@ module Merb module GlobalHelpers # helpers defined here available to all views. + def can_edit? + @post.user_id == current_user.id || is_admin? + end end end diff --git a/app/views/posts/edit.html.erb b/app/views/posts/edit.html.erb index 535101c..04e9365 100644 --- a/app/views/posts/edit.html.erb +++ b/app/views/posts/edit.html.erb @@ -1,3 +1,6 @@ -

Posts controller, edit action

- -

Edit this file in app/views/posts/edit.html.erb

\ No newline at end of file +<% form_for @post, :action => url(:forum_topic_post,@post) do %> + <% fieldset :legend => "Edit Post" do %> +

<%= text_area_control :body, :label => "Body" %>

+

<%= submit_button "Submit" %>

+ <% end %> +<% end %> \ No newline at end of file diff --git a/app/views/topics/show.html.erb b/app/views/topics/show.html.erb index fce3214..4787f83 100644 --- a/app/views/topics/show.html.erb +++ b/app/views/topics/show.html.erb @@ -15,7 +15,7 @@ <%= post.user.login %>
<%= post.user.posts.size %> Posts

- <%= post.body_html %> +
<%= link_to "Edit", url(:edit_forum_topic_post,post) if can_edit? %>
<%= post.body_html %> <% end %>