zoukankan      html  css  js  c++  java
  • Ruby 自学记录 7

    最近面了家公司,用Ruby on Rails,感觉环境很好,HR流程也棒,还有大牛...
    而且他们招聘的是Java,python,并且说明用Ruby做东西.
    这几天看了下,ROR(Ruby on Rails)真的很不错!
    I wishes they give me the offer ~


    rails routes

     article GET    /articles/:id(.:format)                                                                  articles#show
    

    article_controller

    class ArticlesController < ApplicationController
      # define a action
      def new
    
      end
    
      # action create
      def create
        # render show the parameters
        # render plain: params[:article].inspect
    
        # we need to change the create action to use
        #
        ## params[:article] contains the attributes we're interested in
        @article = Article.new(article_params)
        ## saving the model in the database .save will return boolean
        @article.save
        redirect_to @article
      end
    
      private
      def article_params
        params.require(:article).permit(:title,:text)
      end
    end
    
    

    <h1>Listing Articles</h1>
    
    <h1>Hello, Rails!</h1>
    <%= link_to 'My Blog', controller: 'articles' %>
    
    <table>
      <tr>
        <th>Title</th>
        <th>Text</th>
        <th></th>
      </tr>
    
      <% @articles.each do |article| %>
        <tr>
          <td><%= article.title %></td>
          <td><%= article.text %></td>
          <td><%= link_to 'Show', article_path(article) %></td>
        </tr>
      <% end %>
    </table>
    

    I am hungry,the ROR record as this now.

    class ArticlesController < ApplicationController
      # define a action
      def new
    
      end
    
      # index page will show all the articles
      def index
        @articles = Article.all
      end
    
        # after the article submit redirect to this show page
      def show
        @article = Article.find(params[:id])
      end
    
      # action create
      def create
        # render show the parameters
        # render plain: params[:article].inspect
    
        # we need to change the create action to use
        #
        ## params[:article] contains the attributes we're interested in
        @article = Article.new(article_params)
        ## saving the model in the database .save will return boolean
        @article.save
        redirect_to @article
      end
    
      private
      def article_params
        params.require(:article).permit(:title,:text)
      end
    end
    
    
  • 相关阅读:
    Sublime Text2 运行 wxPython
    python BeautifulSoup 安装
    py2exe 打包 MatPlotLib Python
    Pydev无法导入新python模块的解决方案
    WxPython 颜色列表
    股票 API
    (转)Python数组定义
    关于.NET中委托与事件实现整理
    《人月神话》读书笔记
    平面图网络流
  • 原文地址:https://www.cnblogs.com/ukzq/p/13365362.html
Copyright © 2011-2022 走看看