今天重新看了一个半月前在logdown上写的blog,再看了看小伙伴们写的blog,发觉自己真的没有用心去做事情,也没有真正把时间用在刀刃上,没有用心去学编程,白白浪费了许多的时间,这次我是必须要留级来认真重新学编程了,即使在过去的一个半月中,我学到了很多好东西,但是确实是没有精通,很多编程的基础还没有熟练,今天开始,我要每天在简书上markdown下我的日记,坚持每天学习编程。
今天重新看了一次首个课程,也就是rails new first_app这个课程,这次是用atom打开来看的,这次的打开让我如梦初醒,很多在rails101里面的代码其实rails new first_app中是有的,只不过我在学习了之后的课程后,很多东西是已经懂了,但是我还是不够熟悉,也就是说很多东西我只是知道了一点点,但除了课程以外我没有继续去查询资料和用用心学习,作业也没有很用心地去完成,因此我只能说要认真地再来学一遍,这是对我自己没有认真学的一个惩罚,也是对我自己的鞭策。
下面是rails new first_app中的代码:
class TopicsController < ApplicationController
before_action :set_topic, only: [:show, :edit, :update, :destroy]
# GET /topics
# GET /topics.json
def index
@topics = Topic.all
end
# GET /topics/1
# GET /topics/1.json
def show
end
# GET /topics/new
def new
@topic = Topic.new
end
# GET /topics/1/edit
def edit
end
# POST /topics
# POST /topics.json
def create
@topic = Topic.new(topic_params)
respond_to do |format|
if @topic.save
format.html { redirect_to @topic, notice: 'Topic was successfully created.' }
format.json { render :show, status: :created, location: @topic }
else
format.html { render :new }
format.json { render json: @topic.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /topics/1
# PATCH/PUT /topics/1.json
def update
respond_to do |format|
if @topic.update(topic_params)
format.html { redirect_to @topic, notice: 'Topic was successfully updated.' }
format.json { render :show, status: :ok, location: @topic }
else
format.html { render :edit }
format.json { render json: @topic.errors, status: :unprocessable_entity }
end
end
end
# DELETE /topics/1
# DELETE /topics/1.json
def destroy
@topic.destroy
respond_to do |format|
format.html { redirect_to topics_url, notice: 'Topic was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_topic
@topic = Topic.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def topic_params
params.require(:topic).permit(:title, :description, :comment)
end
end