Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added ability to change permalink

  • Loading branch information...
commit 80475b7d06fa757a99552c4a05f5a748ff0371f8 1 parent 37ca1e3
RicSwirrl authored
View
1  app/controllers/articles_controller.rb
@@ -100,6 +100,7 @@ def assign_article_params
@article.title = article_params["title"]
@article.content = article_params["content"]
@article.set_published(article_params["is_published"]=="true", session[:account])
+ @article.set_permalink( article_params["permalink"] ) if article_params["permalink"]
end
def get_article_by_permalink
View
9 app/views/articles/_form.erb
@@ -1,7 +1,12 @@
<% form_for(@article, :url => post_article_path(@article) ) do |f| %>
<p>Title: <%= f.text_field :title %></p>
- <p>Content: </p>
- <%= f.text_area :content, :cols => 60 %>
+<% unless @article.new_record? %>
+ <p>Permalink: <%= f.text_field :permalink %> </p>
+<% end %>
+ <p>
+ Content: (<%= link_to "textile", "http://redcloth.org/hobix.com/textile/quick.html"%> markup)<br/>
+ <%= f.text_area :content, :cols => 60 %>
+ </p>
<p>Published? <%= f.check_box :is_published?, {}, true, false %></p>
<br /><%= f.submit "save" %>
<% end %>
View
12 test/unit/article_test.rb
@@ -33,6 +33,18 @@ def test_no_title
assert_equal "Title must not be blank", a.errors[:title].first
end
+ def test_set_permalink
+ a = Factory.create(:permalink_less_article)
+ assert_equal "this-is-a-title-123", a.permalink
+ a.set_permalink("blah")
+ assert a.save
+ assert_equal "blah", a.permalink
+
+ a.set_permalink("blah&^%")
+ assert a.save
+ assert_equal "blah", a.permalink
+ end
+
def test_title_too_short
a = Article.new
a.title = "ab"
Please sign in to comment.
Something went wrong with that request. Please try again.