This commit is contained in:
ahinz 2014-12-11 15:45:49 +01:00
parent cd73e4810a
commit 3452a81971
3 changed files with 12 additions and 20 deletions

View File

@ -26,7 +26,8 @@ class ArticlesController < ApplicationController
# POST /articles.json # POST /articles.json
def create def create
@article = Article.new(article_params) @article = Article.new(article_params)
@article.created_by = current_user.id
@article.updated_by = current_user.id
respond_to do |format| respond_to do |format|
if @article.save if @article.save
format.html { redirect_to @article, notice: 'Article was successfully created.' } format.html { redirect_to @article, notice: 'Article was successfully created.' }
@ -63,13 +64,13 @@ class ArticlesController < ApplicationController
end end
private private
# Use callbacks to share common setup or constraints between actions. # Use callbacks to share common setup or constraints between actions.
def set_article def set_article
@article = Article.find(params[:id]) @article = Article.find(params[:id])
end end
# Never trust parameters from the scary internet, only allow the white list through. # Never trust parameters from the scary internet, only allow the white list through.
def article_params def article_params
params.require(:article).permit(:title, :content, :rate, :active, :created_by, :updated_by) params.require(:article).permit(:title, :content, :rate, :active, :created_by, :updated_by)
end end
end end

View File

@ -5,14 +5,9 @@ class Article < ActiveRecord::Base
before_destroy :b_destroy before_destroy :b_destroy
def b_create def b_create
self.created_by = current_user.id self.rate = 0.0
self.updated_by = current_user.id
end end
def b_update
self.updated_by = current_user.id
end
def b_destroy def b_destroy
#ToDo destroy comments #ToDo destroy comments
end end

View File

@ -11,8 +11,6 @@
<th><%= model_class.human_attribute_name(:rate) %></th> <th><%= model_class.human_attribute_name(:rate) %></th>
<th><%= model_class.human_attribute_name(:active) %></th> <th><%= model_class.human_attribute_name(:active) %></th>
<th><%= model_class.human_attribute_name(:created_by) %></th> <th><%= model_class.human_attribute_name(:created_by) %></th>
<th><%= model_class.human_attribute_name(:updated_by) %></th>
<th><%= model_class.human_attribute_name(:created_at) %></th>
<th><%=t '.actions', :default => t("helpers.actions") %></th> <th><%=t '.actions', :default => t("helpers.actions") %></th>
</tr> </tr>
</thead> </thead>
@ -24,9 +22,7 @@
<td><%= article.content %></td> <td><%= article.content %></td>
<td><%= article.rate %></td> <td><%= article.rate %></td>
<td><%= article.active %></td> <td><%= article.active %></td>
<td><%= article.created_by %></td> <td><%= article.created %></td>
<td><%= article.updated_by %></td>
<td><%=l article.created_at %></td>
<td> <td>
<%= link_to t('.edit', :default => t("helpers.links.edit")), <%= link_to t('.edit', :default => t("helpers.links.edit")),
edit_article_path(article), :class => 'btn btn-default btn-xs' %> edit_article_path(article), :class => 'btn btn-default btn-xs' %>