view variants support
hksk opened this issue · 3 comments
hksk commented
- What were you trying to do?
add a view variant, example:
$ ls -lah app/views/admin/courses
drwxr-xr-x 7 casa staff 224B May 4 02:17 .
drwxr-xr-x 4 casa staff 128B May 4 01:00 ..
-rw-r--r-- 1 casa staff 2.0K May 4 02:38 show+student.html.erb
-rw-r--r-- 1 casa staff 2.0K May 4 02:38 show.html.erb
- What did you end up with (logs, or, even better, example apps are great!)?
currently in the main controller, cant pass a variant, seems variant: :value not works
# main controller
def show
render locals: {
page: Administrate::Page::Show.new(dashboard, requested_resource)
}
end
so I implemented something like this in my generated controller
# generated controller
def show
variant = ""
if current_user.is_student
variant = "+student"
end
page = Administrate::Page::Show
render "show#{variant}", locals: {
page: Administrate::Page::Show.new(dashboard, requested_resource)
}
end
I guess we can add some like
# main controller
def show
variant = ""
if !request.variant.nil?
variant = "+#{request.variant.to_s}"
end
render render "show#{variant}"locals: {
page: Administrate::Page::Show.new(dashboard, requested_resource)
}
end
# generated controller
def show
request.variant = :student
super
end