在Rails5中,如何在模型上运行更新,然后执行另一个控制器的更新?我知道这是用redirect_to完成的,但不确定具体是如何完成的。这是我到目前为止所知道的:
class BookController < ApplicationController
def update
...
redirect_to author_update_path(id: book.author.id.to_s)
end
end
class AuthorController < ApplicationController
def update
...
red
我有以下代码:
class ArticlesController < ApplicationController
def new
p self.class.object_id
@article = Article.new
end
def create
p self.class.object_id
@article = Article.new(article_params)
if @article.save
redirect_to @article
else
render 'new'
在Rails教程中的Ruby类和继承介绍中,Michael问为什么在Rails控制台中运行static_pages_controller.rb时,一个操作在调用StaticPagesController对象时返回nil:
class StaticPagesController < ApplicationController
def home
end
...
end
rails控制台中的:
>> controller = StaticPagesController.new
=> #<StaticPagesController:0x22855d0>
我创建了一个新的Rails 4.2.1测试项目来尝试新的流媒体特性(我读到的关于的'Live‘特性)。这个项目被设置为使用MySQL作为数据库(我也尝试过Sqlite,但无法重现这个问题)。该项目很简单,只包含: 1)一个具有2个属性(两个字符串)的模型Test。2)简单的路由resources :tests和3)具有一个动作index的简单控制器tests_controller。模型和控制器由标准rails生成器生成,并且只修改了控制器,如下所示:
class TestsController < ApplicationController
include ActionCon