Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add comments

  • Loading branch information...
commit 85dd4c8e91fa06f1691d28156add2682e851542a 1 parent f3e2753
@barthezslavik authored
View
3  app/assets/stylesheets/main.css.sass
@@ -66,3 +66,6 @@ pre
text-decoration: none
font-weight: bold
border: 1px solid #000
+
+#comment_content
+ height: 100px
View
14 app/controllers/comments_controller.rb
@@ -40,17 +40,9 @@ def edit
# POST /comments
# POST /comments.json
def create
- @comment = Comment.new(params[:comment])
-
- respond_to do |format|
- if @comment.save
- format.html { redirect_to @comment, notice: 'Comment was successfully created.' }
- format.json { render json: @comment, status: :created, location: @comment }
- else
- format.html { render action: "new" }
- format.json { render json: @comment.errors, status: :unprocessable_entity }
- end
- end
+ @sample = Sample.find(params[:sample_id])
+ @comment = @sample.comments.create(params[:comment])
+ redirect_to sample_path(@sample)
end
# PUT /comments/1
View
15 app/views/comments/_comment.html.haml
@@ -0,0 +1,15 @@
+%p#notice= notice
+
+%p
+ %b Content:
+ = @comment.content
+%p
+ %b Commentable:
+ = @comment.commentable_id
+%p
+ %b Commentable type:
+ = @comment.commentable_type
+
+= link_to 'Edit', edit_comment_path(@comment)
+\|
+= link_to 'Back', comments_path
View
5 app/views/samples/show.html.haml
@@ -22,6 +22,11 @@
-if @sample.demo?
=link_to "Demo", "/#{@sample.demo}", :class => "link"
+ %br
+ %br
+ = simple_form_for([@sample, @sample.comments.build]) do |f|
+ = f.input :content, :as => :text, :label => false
+ = f.submit "Опубликовать"
/= link_to 'Back', samples_path
View
9 config/routes.rb
@@ -1,14 +1,11 @@
Solution::Application.routes.draw do
- resources :comments
-
-
devise_for :users
resources :categories
-
- resources :samples
-
+ resources :samples do
+ resources :comments
+ end
# The priority is based upon order of creation:
# first created -> highest priority.
Please sign in to comment.
Something went wrong with that request. Please try again.