Skip to content

Instantly share code, notes, and snippets.

@narfdotpl
Created May 4, 2010 11:13
Show Gist options
  • Save narfdotpl/389282 to your computer and use it in GitHub Desktop.
Save narfdotpl/389282 to your computer and use it in GitHub Desktop.
ror: "/profile" instead of "/users/1/edit"
%h1 edit your profile
- form_for @user, :url => {:action => :update} do |form|
%div= form.text_field :name
= error_message_on @user, :name, 'name '
%div= submit_tag 'save'
ActionController::Routing::Routes.draw do |map|
map.root :controller => 'tasks'
map.resources :tasks
map.with_options :controller => :users do |u|
u.edit_user '/profile', :action => :edit, :conditions => {:method => :get}
u.update_user '/profile', :action => :update
end
map.connect ':controller/:action/:id'
map.connect ':controller/:action/:id.:format'
end
# ...
redirect_to edit_user_url#(@current_user)
# ...
class UsersController < ApplicationController
before_filter :signin_required
def edit
@user = User.find(current_user)
end
def update
@user = User.find(current_user)
if @user.update_attributes(params[:user])
redirect_to root_path
else
render :edit
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment