diff --git a/app/controllers/blogs_controller.rb b/app/controllers/blogs_controller.rb index 97a5008..50dee09 100644 --- a/app/controllers/blogs_controller.rb +++ b/app/controllers/blogs_controller.rb @@ -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 diff --git a/app/views/blogs/set_blog.html.haml b/app/views/blogs/set_blog.html.haml new file mode 100755 index 0000000..f6525cd --- /dev/null +++ b/app/views/blogs/set_blog.html.haml @@ -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' \ No newline at end of file