1

I have got a rails controller where the edit action displays a form where all values of the object can be changed. So now when a user accesses /controller/1 I want to do exactly the same as if /controller/1/edit was visited.

I have to achieve this without modifying or adding a route, nor using a redirect_to in the controller. Otherwise JQueryMobile would track the redirect in it's history.

I have tried to do this the ruby way by alias :show :edit but it failed because rails was still searching for show.html.erb

How to do that?

gorootde
  • 4,003
  • 4
  • 41
  • 83

2 Answers2

1

I believe you can define your show action as follows:

def show
  edit
  render :action => :edit
end

but that's really awkward. And it definitely will ignore all before filters if you have any for edit action.

Why can't you use some rules in routes for that? Or better not sending user to show action at all?

KL-7
  • 46,000
  • 9
  • 87
  • 74
0

Add a custom route to map the show action to the edit action.

resources :users, except: :show do
  get "", as: "", on: :member, to: :edit
end
Gerry Shaw
  • 9,178
  • 5
  • 41
  • 45
  • unfortunately, this does not seem to work (tested in rails 4.0.4) because the custom defined routes takes precedence over the ones defined by `resources :users' - this means that a GET to /users/new will trigger the edit action with id: 'new'. – Jeppe Liisberg May 30 '14 at 06:56
  • it can be fixed by hacking the routes to force precedence of the new route - edited the answer to reflect this – Jeppe Liisberg May 30 '14 at 07:05