Skip to content

Commit

Permalink
added can_edit? helper
Browse files Browse the repository at this point in the history
  • Loading branch information
shayarnett committed Mar 22, 2008
1 parent 9935fbf commit 79102e8
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/controllers/posts.rb
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions 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
9 changes: 6 additions & 3 deletions app/views/posts/edit.html.erb
@@ -1,3 +1,6 @@
<h1>Posts controller, edit action</h1>

<p>Edit this file in <tt>app/views/posts/edit.html.erb</tt></p>
<% form_for @post, :action => url(:forum_topic_post,@post) do %>
<% fieldset :legend => "Edit Post" do %>
<p><%= text_area_control :body, :label => "Body" %></p>
<p><%= submit_button "Submit" %></p>
<% end %>
<% end %>
2 changes: 1 addition & 1 deletion app/views/topics/show.html.erb
Expand Up @@ -15,7 +15,7 @@
<%= post.user.login %><br />
<%= post.user.posts.size %> Posts</p>
</td>
<td><%= post.body_html %></td>
<td><div><%= link_to "Edit", url(:edit_forum_topic_post,post) if can_edit? %></div><%= post.body_html %></td>
</tr>
<% end %>
</tbody>
Expand Down

0 comments on commit 79102e8

Please sign in to comment.