Rails 3 render action from another controller

后端 未结 4 2052
攒了一身酷
攒了一身酷 2020-12-01 08:19

I need to render another controller action <%= render \"controller/index\" %> and i get this error

Missing partial controller/inde

4条回答
  •  执念已碎
    2020-12-01 08:24

    If you do not want just to render the view of the other controller (/model), but calling the action (method), think more the ruby way of life - put this method(s) into a module and include it in the controllers you need it.

    I think its less 'spooky' then somehow touching an other controller.

    module StandardActions
        def show_user_homepage(local_params=params)
            #something finding 
            #something to check
            render :"homepage/show" 
        def
    end
    
    class AddressesController < ApplicationController
        include StandardActions
    
        def update
            # update address
            if ok
                show_user_homepage(id: user_id)
            else
                #errorthings
                render :edit #(eg.)
            end
        end         
    end
    
    class HobbiesController  < ApplicationController
        include StandardActions
    
        def update      
            # update hobby
            if ok
                show_user_homepage(id: user_id)
            else
                #errorthings
                render :edit #(eg.)
            end
        end         
    end
    

提交回复
热议问题