blogmodule 0.0.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/app/assets/javascripts/comments.js +2 -0
- data/app/assets/stylesheets/comments.css +4 -0
- data/app/controllers/comments_controller.rb +10 -0
- data/app/helpers/comments_helper.rb +2 -0
- data/app/models/comment.rb +9 -0
- data/app/models/post.rb +2 -0
- data/app/views/comments/_comment.html.erb +6 -0
- data/app/views/comments/_form.html.erb +38 -0
- data/app/views/posts/show.html.erb +3 -7
- data/config/routes.rb +5 -1
- data/db/migrate/20120102163952_create_comments.rb +17 -0
- data/lib/blogmodule/version.rb +1 -1
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/schema.rb +11 -1
- data/test/dummy/log/development.log +2371 -0
- data/test/dummy/tmp/pids/server.pid +1 -0
- data/test/fixtures/comments.yml +11 -0
- data/test/functional/comments_controller_test.rb +9 -0
- data/test/unit/comment_test.rb +7 -0
- data/test/unit/helpers/comments_helper_test.rb +4 -0
- metadata +25 -7
@@ -0,0 +1,10 @@
|
|
1
|
+
class CommentsController < ApplicationController
|
2
|
+
|
3
|
+
def create
|
4
|
+
@post = Post.find(params[:post_id])
|
5
|
+
@comment = @post.comments.build(params[:comment])
|
6
|
+
flash[:alert] = 'Fail to receive the comment. Double check the fields' unless @comment.save
|
7
|
+
|
8
|
+
redirect_to @post
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
class Comment < ActiveRecord::Base
|
2
|
+
belongs_to :post
|
3
|
+
|
4
|
+
|
5
|
+
with_options :allow_blank => true do |c|
|
6
|
+
c.validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i
|
7
|
+
c.validates_format_of :url, :with => /^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?$/ix
|
8
|
+
end
|
9
|
+
end
|
data/app/models/post.rb
CHANGED
@@ -0,0 +1,38 @@
|
|
1
|
+
<%= form_for [post, comment] do |f| %>
|
2
|
+
|
3
|
+
<% if comment.errors.any? %>
|
4
|
+
<div id="error_explanation">
|
5
|
+
<h2><%= pluralize(comment.errors.count, "error") %> prohibited this post from being saved:</h2>
|
6
|
+
|
7
|
+
<ul>
|
8
|
+
<% comment.errors.full_messages.each do |msg| %>
|
9
|
+
<li><%= msg %></li>
|
10
|
+
<% end %>
|
11
|
+
</ul>
|
12
|
+
</div>
|
13
|
+
<% end %>
|
14
|
+
|
15
|
+
<div class="field">
|
16
|
+
<%= f.label :author %><br />
|
17
|
+
<%= f.text_field :author %>
|
18
|
+
</div>
|
19
|
+
|
20
|
+
<div class="field">
|
21
|
+
<%= f.label :email %><br />
|
22
|
+
<%= f.text_field :email %>
|
23
|
+
</div>
|
24
|
+
|
25
|
+
<div class="field">
|
26
|
+
<%= f.label :url %><br />
|
27
|
+
<%= f.text_field :url %>
|
28
|
+
</div>
|
29
|
+
|
30
|
+
<div class="field">
|
31
|
+
<%= f.label :body %><br />
|
32
|
+
<%= f.text_area :body, :rows => 10, :cols => 90 %>
|
33
|
+
</div>
|
34
|
+
|
35
|
+
<div class="actions">
|
36
|
+
<%= f.submit %>
|
37
|
+
</div>
|
38
|
+
<% end %>
|
@@ -1,10 +1,5 @@
|
|
1
1
|
<p id="notice"><%= notice %></p>
|
2
2
|
|
3
|
-
<p>
|
4
|
-
<b>Indexpage:</b>
|
5
|
-
<%= @post.published %>
|
6
|
-
</p>
|
7
|
-
|
8
3
|
<p>
|
9
4
|
<b>Title:</b>
|
10
5
|
<%= @post.title %>
|
@@ -20,8 +15,9 @@
|
|
20
15
|
<%= @post.body %>
|
21
16
|
</p>
|
22
17
|
|
23
|
-
|
24
|
-
|
18
|
+
<hr />
|
19
|
+
<%= render @post.comments || "Nobody commented this post yet." %>
|
20
|
+
<%= render "comments/form", :post => @post, :comment => Comment.new %>
|
25
21
|
|
26
22
|
<%= link_to 'Edit', edit_post_path(@post) %> |
|
27
23
|
<%= link_to 'Back', posts_path %>
|
data/config/routes.rb
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
class CreateComments < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :comments do |t|
|
4
|
+
t.string :author
|
5
|
+
t.string :email
|
6
|
+
t.string :url
|
7
|
+
t.text :body
|
8
|
+
t.references :post
|
9
|
+
|
10
|
+
t.timestamps
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.down
|
15
|
+
drop_table :comments
|
16
|
+
end
|
17
|
+
end
|
data/lib/blogmodule/version.rb
CHANGED
Binary file
|
data/test/dummy/db/schema.rb
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
#
|
12
12
|
# It's strongly recommended to check this file into your version control system.
|
13
13
|
|
14
|
-
ActiveRecord::Schema.define(:version =>
|
14
|
+
ActiveRecord::Schema.define(:version => 20120102163952) do
|
15
15
|
|
16
16
|
create_table "categories", :force => true do |t|
|
17
17
|
t.string "name"
|
@@ -24,6 +24,16 @@ ActiveRecord::Schema.define(:version => 20111231183528) do
|
|
24
24
|
t.integer "category_id", :null => false
|
25
25
|
end
|
26
26
|
|
27
|
+
create_table "comments", :force => true do |t|
|
28
|
+
t.string "author"
|
29
|
+
t.string "email"
|
30
|
+
t.string "url"
|
31
|
+
t.text "body"
|
32
|
+
t.integer "post_id"
|
33
|
+
t.datetime "created_at"
|
34
|
+
t.datetime "updated_at"
|
35
|
+
end
|
36
|
+
|
27
37
|
create_table "posts", :force => true do |t|
|
28
38
|
t.boolean "published"
|
29
39
|
t.datetime "date"
|