0

I have 1 model which is used by 2 controllers - 1 by normal user and 1 by admin user. New/create, edit/update actions are the same in both controllers. I have a shared view which is used by all of the actions but the problem is with form_for in that shared view: For normal user I would have to use:

form_for @my_model, do |f| 

For admin I would have to use:

form_for [:admin, @my_model] do |f|

How can I reuse the view with 2 controllers? Maybe there is a better way of designing this?

Bartłomiej Skwira
  • 1,701
  • 1
  • 16
  • 24

3 Answers3

1

I'm not sure if your design pattern is the best. I suppose you are using partial to share the view, you can actually pass a locals parameter in your partial render:

# user
<%= render :partial => "form", :locals => { :zone => @my_model } %>

# admin
<%= render :partial => "form", :locals => { :zone => [:admin, @my_model] } %>

# your form_for tag in the shared view
form_for(zone) do |f|

I'm not sure if this works, but hope it gives you a heads-up.

You should try using admin namespace method for this.

Community
  • 1
  • 1
Victor
  • 13,010
  • 18
  • 83
  • 146
0

I think you should recall partial.

Paul Brit
  • 5,901
  • 4
  • 22
  • 23
0

As far as I understand, your controllers are basically the same (New/create, edit/update). I would suggest adding a before_filter which tests if the user is an admin and only then gives access to the destroy action. (I'm guessing this is the method which differs).

#Controller
before_filter :admin => :only => [:destroy]
wpp
  • 7,093
  • 4
  • 33
  • 65