完成设置博客信息的功能

This commit is contained in:
meganchen15 2016-01-03 12:46:51 +08:00
parent 812c8bc9ff
commit 5e5310bc93
2 changed files with 33 additions and 1 deletions

View File

@ -1,6 +1,7 @@
#encoding: utf-8
class BlogsController < ApplicationController
before_filter :require_login, only: [:set, :set_userinfo, :upload_img, :set_blog, :update_blog, :change_password, :update_password]
def index
@articles = Article.order('updated_at desc').limit(10)
@new_comments = ArticleComment.order('updated_at desc').limit(10)
@ -37,7 +38,19 @@ class BlogsController < ApplicationController
end
def update_blog
param_hash = params.require(:blog).permit(:name, :blog_title, :email, :description)
@blog = BlogInfo.first
if @blog.present?
result = @blog.update_attributes param_hash
else
@blog = BlogInfo.new param_hash
result = @blog.save
end
if result
redirect_to set_blogs_path
else
render 'set_blog'
end
end
def about

View File

@ -0,0 +1,19 @@
.row
%h3.set_title 设置
= render 'set_sidebar', obj: @blog
.col-md-8
= form_for @blog, as: 'blog', url: update_blog_blogs_path, method: 'post', role: 'form' do |f|
.form-group
%label{for: 'blog_name'} 博主
= f.text_field :name, placeholder: '博主名称', class: 'form-control'
.form-group
%label{for: 'blog_blog_title'} 博客名字
= f.text_field :blog_title, placeholder: '博客名称', class: 'form-control'
.form-group
%label{for: 'blog_email'} 联系邮箱
= f.text_field :email, placeholder: '联系邮箱', class: 'form-control'
.form-group
%label{for: 'blog_description'} 关于博主
= f.text_area :description, placeholder: '关于博主', class: 'form-control blog-description'
.form-group
= f.submit '修改', class: 'btn btn-primary set-btn'