i got a simple rails app for browser bookmarks.
image here
a bookmark, seen on the top, is a folder that contains the subcategory folders in the left sidebar.
when clicking a folder on the left one gets the bookmarks listing of the folder. i.e. a bookmarks#index with params. same is folder#index with params on the left and top. how can i render all the 3 controller action on one page?
-
You can use partials. Checkout guides.rubyonrails.org/…Imran Ahmad– Imran Ahmad2018-05-25 11:05:15 +00:00Commented May 25, 2018 at 11:05
-
@user9675688 checkout the given answer below, i believe it will be helpful for you, let me know for further guidance.Anand– Anand2018-05-25 11:16:36 +00:00Commented May 25, 2018 at 11:16
Add a comment
|
2 Answers
Well you can definitely render to a common page from different actions, see the example:-
in bookmarks_controller.rb
def index
#do your stuffs
render "path_of_comman_page",locals: {x: "foo", y: "bar"}
end
in folder_controller.rb
def index
#do your stuffs
render "path_of_comman_page",locals: {x: "foo", y: "bar"}
end
So here by you will be able to access all locals variable at your comman page. like x, y
path_of_comman_page can be for example /bookmarks/listings which means you are rendering data to bookmarks controller listings.html.erb
Alternative it can be done by common partial for example
def index
#do your stuffs...
respond_to do |format|
format.html { render partial: "listings/listing", locals: {x: "foo", y: "bar"}}
end
end
Comments
actually i want it like this, somehow with js. maybe it's possible with a controller too ... folders/index.haml
.container_top
- @folders.each do |f|
- if f.is_rootparent?
-# send ajax to fetch subcategory folders!
=link_to folder_path(parent: f), remote: true do
.bookmark_vertical
%p = f.title
.container_left
#appendsubcategoryfoldershere