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
    
    
  • 相关阅读:
    Makefile 之 $(Q)
    LeetCode-50-Pow(x, n)
    LeetCode-49. Group Anagrams
    全排列问题全面解析
    LeetCode-47. Permutations II
    LeetCode-46. Permutations
    LeetCode-43. Multiply Strings
    LeetCode-40. Combination Sum II
    LeetCode-39. Combination Sum
    LeetCode-36. Valid Sudoku
  • 原文地址:https://www.cnblogs.com/ukzq/p/13365362.html
Copyright © 2011-2022 走看看