新手问题 在一个 controller 中调用另一个 controller 中的 action?

cqcn1991 · 2013年01月18日 · 最后由 vkill 回复于 2013年01月18日 · 4739 次阅读

原题来自 ruby on rails tutorial 中的 message extention: Messaging Twitter supports direct (private) messaging by prefixing a micropost with the letter“d”. Implement this feature for the sample application. The solution will probably involve a Message model and a regular expression match on new microposts.

也就是说 要在 micropost controller 中调用 message controller 中的 create:

micropostcontroller
 def create
    @micropost =current_user.microposts.build(params[:micropost])
        if 首字母为d 
              **micropost创建message** 
       else 
                    正常创建@micropost


 end

我查了一下,不知道是不是这样写:? message = Message.create(@micropost)

见于http://stackoverflow.com/questions/10200591/rails-create-two-objects-at-the-same-time-one-of-which-uses-the-id-of-the-othe

写的代码怎么缩进额……

TestsController.action(:test).call(env)

但是这样意义不大,基本上都是在 middleware 和 routes.rb 中这样用,action 中这样调没啥意义。

需要 登录 后方可回复, 如果你还没有账号请 注册新账号