Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>One suggestion on the 'what' of your question: instead of the ideal url being localhost:3000/users/current_user I suggest <strong>localhost:3000/user</strong> or something even more descriptive such as <strong>localhost:3000/profile</strong> or <strong>localhost:3000/account</strong>.</p> <p>Could you include the entries in your routes.rb? Even if Authlogic, etc. add routes to your app, they should do it in routes.rb. If you have the entry:</p> <pre><code>map.resource :users </code></pre> <p>then that's where the /users/123 route is coming from. I agree with Matchu that even if you don't use /users/123 you should keep it and route other requests to it. </p> <p><strong>An Additional Idea</strong> If you don't want to get into the (kinda complicated, and not pretty) business of preserving model validation errors across redirects, here's another way. I'm assuming from here that you already have map.resource :users, so that you have the 7 default actions on your UsersController (index, new, create, show, edit, update, destroy).</p> <p>In your routes.rb:</p> <pre><code>map.profile 'profile', :controller =&gt; 'users', :action =&gt; 'show' map.edit_profile 'profile/edit', :controller =&gt; 'users', :action =&gt; 'edit', :conditions =&gt; { :method =&gt; :get } map.update_profile 'profile/edit', :controller =&gt; 'users', :action =&gt; 'update', :conditions =&gt; { :method =&gt; :put } </code></pre> <p>You will need to update your form_for tag slightly:</p> <pre><code>&lt;% form_for @user, :url =&gt; update_profile_path do |f| %&gt; ... </code></pre> <p>Now, assuming you start on /profile, and click an edit link that takes you to /profile/edit (should show the form), if you fill out the form such that it fails validation then you should end up back on /profile/edit with the correct errors in the f.error_messages output.</p> <p>Your controller code for edit should stay the same, and your code for update should be:</p> <pre><code>def update @user = current_user || User.find(params[:id]) if @user.update_attributes(params[:user]) flash[:notice] = "Successfully updated user." redirect_to @user else render :action =&gt; 'edit' end end </code></pre> <p>The render (rather than a redirect) preserves the state of the @user model (including errors) and just renders the edit template again. Since you directed it at the update_profile_path the url viewed by the user is still /profile/edit.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload