routing in rails - displaying the contents of one controller in a different view -


i trying figure out how routes contents of 1 controller of another. currently, have 2 controllers -
1. static pages controller - simple, used yield 1 page (with tabbable pages)

class staticpagescontroller < applicationcontroller   def home   end end 

2.guides controller - user may (currently) add guides db.

class guidescontroller < applicationcontroller   def home   end    def show    @guide = guide.find(params[:id])   end    def index     @guide = guide.all   end    def new    @guide = guide.new   end   def create    @guide = guide.new(guide_params)    if @guide.save      redirect_to '/guides'    else     render 'new'   end end  private  def guide_params   params.require(:guide).permit(:title, :description, :image, :date, :date_end, :extra_info) end 

end

i want display index part of controller (which works @ '/guides', in root directory, or 'home' in static pages controller.

i've tried fiddling of this, , last port of call routes.rb file. not sure, seems straight forward enough , cheesing me off not being able it.

one of possible solutions use:

class staticpagescontroller < applicationcontroller   def home      @guide = guide.all   end end 

and copy code index,html.erb of guide home.html.erb of static pages. other can use rendering: link

edit:

use partial show index of guides:

class guidescontroller < applicationcontroller    def index     @guide = guide.all     render partial: "index"   end end 

in views of guide rename "index.html.erb" "_index.html.erb" , in static_pages/home.html.erb add:

<%= render :partial => "guides/index" %> 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -