简体   繁体   English

Ruby on Rails的第一步

[英]Ruby on Rails first steps

I have installed ROR+apache2 on my Linux VM (TurnKey Rails VM image) and making first steps folowing http://guides.rubyonrails.org/getting_started.html this guide 我在我的Linux VM(TurnKey Rails VM映像)上安装了ROR + apache2,并在http://guides.rubyonrails.org/getting_started.html本指南中做了第一步

i have stucked on adding resource calling articles. 我一直坚持添加资源调用文章。 What i have done my routes.rb: 我做了什么路线.rb:

root@rails www/blog# cat ./config/routes.rb 
Blog::Application.routes.draw do

  resources :articles

  root 'welcome#index'



end

my rake routes 我的佣金路线

root@rails www/blog# rake routes
      Prefix Verb   URI Pattern                  Controller#Action
    articles GET    /articles(.:format)          articles#index
             POST   /articles(.:format)          articles#create
 new_article GET    /articles/new(.:format)      articles#new
edit_article GET    /articles/:id/edit(.:format) articles#edit
     article GET    /articles/:id(.:format)      articles#show
             PATCH  /articles/:id(.:format)      articles#update
             PUT    /articles/:id(.:format)      articles#update
             DELETE /articles/:id(.:format)      articles#destroy
        root GET    /                            welcome#index

then folowing guide: 然后是以下指南:

rails g controller articles

after that in browser "/" working fine, im getting my "hello, rails" but "/articles/" or "/articles/new" returns 404 - not found. 之后在浏览器“/”工作正常,我得到我的“你好,铁路”但“/ articles /”或“/ articles / new”返回404 - 未找到。 (The page you were looking for doesn't exist.) (您要查找的页面不存在。)

my views folder 我的观点文件夹

views  ls -al
total 20
drwxrwxrwx 5 www-data www-data 4096 Jun 10 05:02 .
drwxrwxrwx 8 www-data www-data 4096 Jun 10 04:40 ..
drwxrwxrwx 2 www-data www-data 4096 Jun 10 05:02 articles
drwxrwxrwx 2 www-data www-data 4096 Jun 10 04:40 layouts
drwxrwxrwx 2 www-data www-data 4096 Jun 10 04:49 welcome

my article controller code: 我的文章控制器代码:

class ArticlesController < ApplicationController
end

Many time spended Google has no result 很多时候谷歌没有结果

The question is what am i doing wrong, and how can i debug this like issues. 问题是我做错了什么,我如何调试这个问题。 Thx! 谢谢!

The last part of the URL tells Rails which controller and which action in the controller should be called. URL的最后一部分告诉Rails应该调用哪个控制器和控制器中的哪个动作。 For your example: /actions/new refers to the controller 'actions_controller.rb' and to the action 对于您的示例:/ actions / new指的是控制器'actions_controller.rb'和操作

def new
end

If you do not define something in your controller action rails will show the view which has the same name as your controller action. 如果未在控制器中定义某些操作,则rails将显示与控制器操作同名的视图。 In this case you must have this file: 在这种情况下,您必须拥有此文件:

views\actions\new.html.erb

I guess this is the file you haven't created yet. 我猜这是你还没有创建的文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM