views:

22

answers:

2

I am not sure if I am going about this the right way or not.

I have a model Neighborhood. I have a two ways you can add a neighborhood, one as a logged in user and the other as a public person. The forms vary a bit. So I made another view with a custom action. The problem is this action is adding a new record and therefore calls on "create." When it calls the create action it looks to redirect to a path that cannot exist on the public form.

Either I am doing this completely wrong or there is a way to tell my custom action to save the Neighborhood record so I can redirect on the public side.

A: 

In the create action, conditionally redirect to either the public / private page depending on the user's status:

def create
  # create code goes here
  if current_user?
    redirect_to neighborhoods_path
  else
    redirect_to root_path
  end
end

Or is there something that I am not understanding from your question?

Ryan Bigg
thanks a lot ryan this is exactly the extra guidance I needed. appreciate it.
looloobs
A: 

Hi looloobs,

i think you are saving both (public and registered users), the Neighborhood details are added to the same details. you might different this by having a user id or something

if so, As i see you can use the same controller and action. All you have to do is

identify the user like is_registred? (provided that you have a method to identify if a use is logged or not) and according to the user load layout only

Ex:

pseudo code would be

if is_registred?
   render public layout
else
   render registerd user layout   

and you might have to check authorizations as well. Hope I understood your question

cheers

sameera

sameera207