【发布时间】:2010-12-01 05:21:16
【问题描述】:
我是一名 .NET 开发人员,正在转向 Ruby on Rails。我一直在 ASP.NET MVC 中编程,现在尝试将相同的概念应用于 Rails。我创建了索引操作,现在当我说 home/index 时,它会自动重定向我不存在的“显示”操作。我的 routes.rb 文件有这一行:
资源:主页
home 是 home_controller。
我做错了什么?
class HomeController < ApplicationController
def show
end
# show all the articles
def index
@articles = Array.new[Article.new,Article.new,Article.new]
respond_to do |format|
format.html
format.xml { render :xml => @articles }
end
end
def new
@article = Article.new
respond_to do |format|
format.html
format.xml { render :xml => @article }
end
end
def create
@article = Article.new(params[:post]);
if @article.save
format.html { redirect_to(@post,
:notice => 'Post was successfully created.') }
end
end
def confirm
end
end
【问题讨论】:
-
你的控制器是什么样的?
-
我更新了上面的代码以包含控制器的实现!
标签: ruby-on-rails