I have a really basic Rails 7 application at the moment. Using all the defaults.
For some reason, Rails is not entering/running the code within a controller I've defined.
Here is the related route.
scope module: 'admin', path: 'admin', as: 'admin' do
root 'home#index'
resources :users do
post :invite, on: :collection
end
end
Here is the related Controller method:
def invite
puts "INVITE" * 100
invite_params = params.require(:admin_invite).permit(:name, :email)
#invite = Admin::Invite.new(invite_params)
respond_to do |f|
if #invite.send_invite
f.html { redirect_to admin_users_url, notice: "Invite sent" }
else
f.html { redirect_to admin_users_url, status: :unprocessible_entity, error: "There was an error sending the invite" }
end
end
end
Here is the form that POSTs to that route.
= form_with model: #new_invite, url: invite_admin_users_url, html: {"data-turbo" => false} do |f|
= f.label :name
= f.text_field :name
= f.label :email
= f.email_field :email
= f.submit "Invite"
I thought maybe it had something to do with TURBO that comes with Rails 7, so I disabled it on this form, but it didn't resolve the issue.
When I click submit on that form, I get the following error: No template found.
Looking at the output in the terminal, it seems to be POSTing properly to the controller, but it's not running any of the code with the method. Even that puts statement I have at the beginning of the #invite method doesn't execute.
19:26:14 web.1 | Started POST "/admin/invite_user" for ::1 at 2022-09-07 19:26:14 -0400
19:26:14 web.1 | Processing by Admin::UsersController#invite as HTML
19:26:14 web.1 | Parameters: {"authenticity_token"=>"[FILTERED]", "admin_invite"=>{"name"=>"Test", "email"=>"test#test.com"}, "commit"=>"Invite"}
19:26:14 web.1 | User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2 [["id", 1], ["LIMIT", 1]]
19:26:14 web.1 | No template found for Admin::UsersController#invite, rendering head :no_content
Any ideas?
Related
I'm using the carrierwave gem to upload images
I have this form in my users view which provides an upload button for a file (image)
<%= form_for(#user, html: { multipart: true }) do |f| %>
Update your profile pic:
<span class="avatar">
<%= f.file_field :avatar %>
</span>
<%= f.submit "Update", class: "btn btn-primary" %>
<% end %>
Here's my users controller
class UsersController < ApplicationController
def show
#user = User.find(params[:id])
end
def update
#user = User.find(params[:id])
end
private
def user_params
params.require(:user).permit(:avatar)
end
end
When I click the submit button on the form from the browser, I get this http request come through.
Started PATCH "/users/1" for 127.0.0.1 at 2018-07-05 13:15:39 +0100
Processing by UsersController#update as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"VXaEvnTD7nl+2d/0n1+iB/zwRX+Mf3nbMt0/Qr7m/nYpTmyXCxih981pIbGKGT9qdSfB7zyB6l
CKGdA9uiLouw==", "user"=>{"avatar"=>#<ActionDispatch::Http::UploadedFile:0x00007fbf2a794af0 #tempfile=#<Tempfile:/var/folders
/42/plkmf9zn755b0lvwc2_5k30c0000gn/T/RackMultipart20180705-37847-7s1tba.png>, #original_filename="Screen Shot 2018-07-03 at 1
0.23.17.png", #content_type="image/png", #headers="Content-Disposition: form-data; name=\"user[avatar]\"; filename=\"Screen S
hot 2018-07-03 at 10.23.17.png\"\r\nContent-Type: image/png\r\n">}, "commit"=>"Update", "id"=>"1"}
User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2 [["id", 1], [
"LIMIT", 1]]
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
No template found for UsersController#update, rendering head :no_content
Completed 204 No Content in 161ms (ActiveRecord: 0.6ms)
But nothing is updated in the database (i.e. the avatar attribute for the current user still has a value of nil). I also can't see that the image has been saved anywhere.
It's your controller update method which is incomplete, for example :
def update
user = User.find(params[:id]) # Set user
if user.update(user_params) # Save to database
# Success, redirect to show/index/whatever
else
# Fail, render form again
end
end
And i recommend you to read this: http://guides.rubyonrails.org/action_controller_overview.html
I've been battling for days now to get data to save for my nested form. I basically want to be able to store a users reason for cancelling a project, along with the last stage of the project before it was cancelled. But I just can't seem to get the actions cancel, cancel_save, and cancel_params to play nicely!
Controller
before_action :correct_user, only: [:show, :edit, :update, :destroy, :cancel, :cancel_save]
...
def cancel
#project.build_project_close_reason
end
def cancel_save
#project.build_project_close_reason(cancel_params)
#project.update(project_status_id: 10)
redirect_to root_path, notice: 'Project has been successfully cancelled.'
end
private
def correct_user
#user = current_user
#project = current_user.projects.find_by(id: params[:id])
end
redirect_to user_projects_path, notice: "You are not authorised to view this project" if #project.nil?
end
def cancel_params
params.require(:project).permit(project_close_reason_attributes: [:comment]).merge(project_close_reason_attributes: [project_id: #project.id, last_status_id: #project.project_status_id ])
end
Models
class Project < ApplicationRecord
belongs_to :user
has_one :project_close_reason
accepts_nested_attributes_for :project_close_reason #adding this seemed to make no difference?
end
class ProjectCloseReason < ApplicationRecord
belongs_to :project
end
class User < ApplicationRecord
... # All standard devise stuff
has_many :projects
end
Nested form in the view
<%= form_for([#user, #project], url: {action: "cancel_save"}, method: :post) do |f| %>
<%= fields_for :project_close_reason do |pcr| %>
<div class="field entry_box">
<%= pcr.label "Why are you cancelling this project? (This helps us improve!)" %>
<%= pcr.text_area :comment, class: "form-control entry_field_text" %>
</div>
<% end %>
<div class="actions center space_big">
<%= f.submit "Cancel Project", class: "btn btn-lg btn-warning" %>
</div>
<% end %>
Routes
devise_for :users
devise_for :admins
resources :users do
resources :projects do
get "cancel", :on => :member
post "cancel" => 'projects#cancel_save', :on => :member
end
end
This is the error I get when I try and submit the form:
ActionController::ParameterMissing in ProjectsController#cancel_save
param is missing or the value is empty: project. It references the cancel_params action
Thanks for any help!
UPDATE
Here is the log when I call cancel_save
Started POST "/users/2/projects/10/cancel" for ::1 at 2016-09-29 10:03:44 +0200
Processing by ProjectsController#cancel_save as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"h6K+VFyjW/dV189YOePWZm+Pmjey50xAMQIJb+c3dzpEaMv8Ckh3jQGOWfVdlfVH/FxolbB45fXvTO0cdplhkg==", "project_close_reason"=>{"comment"=>"b"}, "commit"=>"Cancel Project", "user_id"=>"2", "id"=>"10"}
User Load (11.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2 [["id", 2], ["LIMIT", 1]]
Project Load (0.7ms) SELECT "projects".* FROM "projects" WHERE "projects"."user_id" = $1 AND "projects"."id" = $2 LIMIT $3 [["user_id", 2], ["id", 10], ["LIMIT", 1]]
ProjectCloseReason Load (0.2ms) SELECT "project_close_reasons".* FROM "project_close_reasons" WHERE "project_close_reasons"."project_id" = $1 LIMIT $2 [["project_id", 10], ["LIMIT", 1]]
Completed 400 Bad Request in 22ms (ActiveRecord: 12.1ms)
ActionController::ParameterMissing (param is missing or the value is empty: project):
The error is saying that there is no params with name project, which you are trying to require in params.require(:project) line in cancel params. I think this is happening beacause in form_for you have mentioned [#user, #project], that means user's project. So the project params must be inside user's. Check your log when you call cancel_save. There must be something like {user => {project => { } }.
In the end I got it to work without requiring projects at all. This is my revised cancel_params in my projects_controller. For anyone else looking at doing this kind of additive databasing, I highly recommend skipping params for nested form if you can do it this way. So much simpler!
private
def cancel_params
params.require(:project_close_reason).permit(:comment).merge(project_id: #project.id, last_status_id: #project.project_status_id )
end
Devise's sign_in_after_reset_password setting supposedly signs in my user after successfully resetting the password.
However, what it seems to do in practice is to redirect back to '/', which ultimately results in showing the login page.
Why isn't it signing me in?
In user.rb:
devise :database_authenticatable,
:recoverable,
:validatable,
:encryptable
In application_controller.rb:
class ApplicationController < ActionController::Base
protect_from_forgery
before_action :authenticate_user!, unless: :devise_controller?
#omitting business logic filters and helpers
end
Custom routes (solely to change the paths. Have tried to keep the resulting route list identical to the defaults other than the names):
devise_for :users, skip: [ :passwords, :sessions ]
devise_scope :user do
get 'users/login' => 'devise/sessions#new', as: 'new_user_session'
post 'users/login' => 'devise/sessions#create', as: 'user_session'
delete 'users/logout' => 'devise/sessions#destroy', as: 'destroy_user_session'
post 'users/password' => 'devise/passwords#create', as: 'user_password'
get 'users/password/forgot' => 'devise/passwords#new', as: 'new_user_password'
get 'users/password/reset' => 'devise/passwords#edit', as: 'edit_user_password'
patch 'users/password' => 'devise/passwords#update', as: nil
put 'users/password' => 'devise/passwords#update', as: nil
end
The investigation so far:
I had a lot of minor deviations from the structure of a sample devise application which I have been golfing back bit by bit to try and make things easier to figure out. So now my authenticate_user! filter is being specified in the same place as most examples.
Something I noticed is that after successfully resetting the password, it isn't clearing the reset password token. Maybe that's normal, it's just suspicious.
I have debugged in Devise's PasswordsController itself and after it executes the sign_in line, signed_in? does return true.
I have attempted to breakpoint inside signed_in? at the point of requesting the root path, but it seems like I get the 401 error from the web server without signed_in? ever being called. So perhaps Warden is directly kicking me out before the application even gets to run.
I'm starting to run out of avenues for investigation, so I thought I would post it here in case anyone had seen the exact same issue before.
Logs of the event:
Started PUT "/users/password" for ::1 at 2016-07-13 17:14:44 +1000
Processing by Devise::PasswordsController#update as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"[FILTERED]", "user"=>{"reset_password_token"=>"[FILTERED]", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"Change my password"}
Can't verify CSRF token authenticity
User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."reset_password_token" = ? ORDER BY "users"."id" ASC LIMIT 1 [["reset_password_token", "[FILTERED]"]]
(0.0ms) begin transaction
Note Load (0.1ms) SELECT "notes".* FROM "notes" WHERE "notes"."notable_id" = ? AND "notes"."notable_type" = ? [["notable_id", 2], ["notable_type", "User"]]
Organisation Load (0.1ms) SELECT "organisations".* FROM "organisations" WHERE "organisations"."id" = ? LIMIT 1 [["id", 1]]
User Exists (0.1ms) SELECT 1 AS one FROM "users" WHERE ("users"."login" = 'test1' AND "users"."id" != 2) LIMIT 1
(0.0ms) commit transaction
Redirected to http://localhost:3000/
User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT 1 [["id", 2]]
Completed 302 Found in 44ms (ActiveRecord: 1.7ms)
Started GET "/" for ::1 at 2016-07-13 17:14:44 +1000
Processing by SessionsController#welcome as HTML
Completed 401 Unauthorized in 0ms (ActiveRecord: 0.0ms)
Started GET "/users/login" for ::1 at 2016-07-13 17:14:44 +1000
Processing by Devise::SessionsController#new as HTML
Rendered users/shared/_links.html.erb (0.1ms)
Rendered users/sessions/new.html.erb within layouts/application (2.2ms)
Completed 200 OK in 148ms (Views: 147.3ms | ActiveRecord: 0.0ms)
Not really answering the question itself, but I found a workaround which is at least a solution, even if it's a bad solution.
In my ApplicationController:
after_action :fix_login_after_password_reset, if: ->(controller) {
controller.controller_path == 'devise/passwords' &&
controller.action_name == 'update'
}
def fix_login_after_password_reset
user = current_user
if user && user.errors.empty?
user = User.where(id: user.id).first
sign_out
bypass_sign_in(user)
end
end
Essentially, I found a post where people who wrote their own "change password" pages found that Devise (or Warden?) was logging out the user immediately afterwards. The workaround for them was to change the call to sign_in to bypass_sign_in.
In this situation, though, Devise have already called sign_in. So I thought I'd try adding a filter that applies onto to their one action with the problem, and sign the user out, then sign in a fresh copy of the user. This fixes the issue - now the user is signed in and the root page appears.
I don't like this solution much though so I'm still digging inside Warden to try and figure out why the user is not being signed in with a call to sign_in.
I had the same issue, and found that passing an extra parameter to the sign_up function solves the problem:
sign_in(#user, :bypass => true)
This was something I found in this tutorial for setting up omniauth with a finish_signup feature. My implementation below is part of a feature I'm writing for a user to change their password and still retain their status as a logged in user.
~/app/controllers/users_controller.rb
class UsersController < ApplicationController
before_action :set_current_user, only: [:edit_password, :update_password]
def edit_password
end
def update_password
if #user.update(user_params)
# Sign in the user by passing validation in case their password changed
sign_in(#user, :bypass => true)
redirect_to root_path
else
render :edit_password
end
end
private
def set_current_user
#user = User.find(current_user.id)
end
end
~/app/views/users/edit_password.html.erb
<%= form_for(#user, :url => { :action => "update_password" } ) do |f| %>
<div class="field">
<%= f.label :password, "Password" %><br />
<%= f.password_field :password, :autocomplete => "off" %>
</div>
<div class="field">
<%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation %>
</div>
<div class="action_container">
<%= f.submit %>
</div>
<% end %>
routes.rb
resource :user, only: [:none] do
collection do
get :edit_password
patch :update_password
end
end
I have a projects model and a task model, however a task can have many projects and vice versa...so i created a relationship model between the two. Now from the project profile, i want to be able to create a task and automatically have it create the task and the relationship between the new task and the project it was created from.
However when i try to accomplish this i am getting the following error:
ActiveRecord::RecordNotFound in TasksController#create
Couldn't find Project with 'id'=
A user is on the Project show page and clicks a link to 'submit new task'. I realize i'm not passing the project ID somehow but I can't seem to figure out how to do this because I'm using a TaskRelationship model to associate the task and the project (I'm not nesting the task in the project in my routes).
views/projects/show.html.erb:
<%= link_to "+ Submit New Task", new_task_path, :class => "btn btn-info col-md-12" %>
From the new tasks view, I need to create both the task and the relationship between task and project.
views/tasks/new.html.erb:
<div class="container sign-in-register">
<div class="authform">
<%= form_for #task, :html => {:multipart => true} do |f| %>
<h3>Submit new task to this project...</h3><br/>
<%= render 'shared/error_messages', object: f.object %>
<%= f.label :Title %>
<%= f.text_field :title, class: 'form-control' %>
<%= f.label :Description %>
<%= f.text_area :description, class: 'form-control' %>
<br clear="all">
<%= f.submit "Add this Task", class: "btn btn btn-info" %>
<% end %>
</div>
</div>
TaskRelationship Model (links tasks to projects):
class TaskRelationship < ActiveRecord::Base
belongs_to :taskproject, class_name: "Project"
belongs_to :projecttask, class_name: "Task"
validates :taskproject_id, presence: true
validates :projecttask_id, presence: true
end
Project Model:
class Project < ActiveRecord::Base
belongs_to :owner, :foreign_key=>'user_id', :class_name=>'User'
has_many :tasks
has_many :taskrelationships, foreign_key: "taskproject_id", dependent: :destroy
has_many :projecttasks, through: :taskrelationships, source: :projecttask
validates :title, presence: true
validates :background, presence: true
def related?(some_task)
taskrelationships.find_by_projecttask_id(some_task.id)
end
def relate!(some_task)
self.taskrelationships.create!(projecttask_id: some_task.id)
end
end
Task Model:
class Task < ActiveRecord::Base
belongs_to :owner, :foreign_key=>'user_id', :class_name=>'User'
has_many :projects
has_many :reverse_taskrelationships, foreign_key: "projecttask_id",
class_name: "TaskRelationship",
dependent: :destroy
has_many :taskprojects, through: :reverse_taskrelationships, source: :taskproject
validates :title, presence: true
validates :description, presence: true, length: { maximum: 140 }
end
Tasks Controller:
class TasksController < ApplicationController
def new
#task = Task.new
end
def create
#project = Project.find(params[:taskproject_id])
#task = current_user.own_tasks.build(task_params)
if #task.save
flash[:success] = "Your task has been created."
redirect_to #task
#project.relate!(#task) unless #project.related?(#task) # establish task relationship w/ project only if doesn't exist
else
render 'task'
end
end
private
def task_params
params.require(:task).permit(:title, :description, :user_id, task_relationship_attributes: [:taskproject_id, :projecttask_id])
end
end
Task_Relationships_Controller:
class TaskRelationshipsController < ApplicationController
before_filter :authenticate_user!
def create
end
def destroy
end
# I assume (maybe incorrectly) that i don't need create/destroy actions but do need strong params
private
def task_relationship_params
params.require(:taskrelationship).permit(:taskproject_id, :projecttask_id)
end
end
How can i get this correct ID passed so that the new task is created and the new taskRelationship between task and project? thx,
UPDATE:
I've added the log for more detail
Terminal Log when trying to post:
Started GET "/tasks/new" for ::1 at 2016-04-15 19:55:54 -0500
Started GET "/tasks/new" for ::1 at 2016-04-15 19:55:54 -0500
Processing by TasksController#new as HTML
Processing by TasksController#new as HTML
Rendered shared/_error_messages.html.erb (0.1ms)
Rendered shared/_error_messages.html.erb (0.1ms)
Rendered tasks/new.html.erb within layouts/application (24.5ms)
Rendered tasks/new.html.erb within layouts/application (24.5ms)
Rendered layouts/_shim.html.erb (0.0ms)
Rendered layouts/_shim.html.erb (0.0ms)
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT 1 [["id", 4]]
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT 1 [["id", 4]]
Rendered layouts/_navigation_links.html.erb (1.6ms)
Rendered layouts/_navigation_links.html.erb (1.6ms)
Rendered layouts/_header.html.erb (2.9ms)
Rendered layouts/_header.html.erb (2.9ms)
Rendered layouts/_footer.html.erb (0.0ms)
Rendered layouts/_footer.html.erb (0.0ms)
Completed 200 OK in 192ms (Views: 185.6ms | ActiveRecord: 1.0ms)
Completed 200 OK in 192ms (Views: 185.6ms | ActiveRecord: 1.0ms)
Started POST "/tasks" for ::1 at 2016-04-15 19:55:59 -0500
Started POST "/tasks" for ::1 at 2016-04-15 19:55:59 -0500
Processing by TasksController#create as HTML
Processing by TasksController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"DGGG+zWPMbB7OwZz8oCVLB5O6sMfTe/Orj6KfeP6mrveOH0ImAP4aow0gufqefOdwsp8v4GDEt8ppJiL4CvQVg==", "task"=>{"title"=>"test", "description"=>"test"}, "commit"=>"Add this Evidence"}
Parameters: {"utf8"=>"✓", "authenticity_token"=>"DGGG+zWPMbB7OwZz8oCVLB5O6sMfTe/Orj6KfeP6mrveOH0ImAP4aow0gufqefOdwsp8v4GDEt8ppJiL4CvQVg==", "task"=>{"title"=>"test", "description"=>"test"}, "commit"=>"Add this Evidence"}
Project Load (0.3ms) SELECT "projects".* FROM "projects" WHERE "projects"."id" = $1 LIMIT 1 [["id", nil]]
Project Load (0.3ms) SELECT "projects".* FROM "projects" WHERE "projects"."id" = $1 LIMIT 1 [["id", nil]]
Completed 404 Not Found in 2ms (ActiveRecord: 0.3ms)
Completed 404 Not Found in 2ms (ActiveRecord: 0.3ms)
ActiveRecord::RecordNotFound (Couldn't find Project with 'id'=):
app/controllers/tasks_controller.rb:8:in `create'
ActiveRecord::RecordNotFound (Couldn't find Project with 'id'=):
app/controllers/tasks_controller.rb:8:in `create'
1) You'll need to pass the project ID to TasksController#new somehow.
One approach is to pass it as part of the request URL, something like:
<host>/tasks/new?project_id=<project ID>
This will make it available in the params variable of the request.
2) In your TasksController#new action, pass project_id from params to the view. The easiest way is using an instance variable:
#project_id = params[:project_id]
There is a philosophy of only passing one object to a view and here we're passing 2: #task and #project_id. I wouldn't worry about it but you might want to read up on form objects: https://robots.thoughtbot.com/activemodel-form-objects
3) Add a hidden field on your form with the project ID. Because #project_id isn't part of the #task model, we'll use an input tag helper instead of a form based helper:
<%= hidden_field_tag 'project_id', #project_id %>
API doc: http://apidock.com/rails/ActionView/Helpers/FormTagHelper/hidden_field_tag
Now the value of #project_id will be passed to the #create action as params[:project_id] when the user clicks on the submit button.
4) Change the params in TasksController#create action. project_id will be nested in with the task parameters:
#project = Project.find(params[:project_id])
5) You'll need to create your TaskRelationship relationship. There are a couple of ways to do this. I usually use build:
#task.taskprojects.build(project: #project)
so your #create action would look something like:
#project = Project.find(params[:project_id])
#task = current_user.own_tasks.build(task_params)
#task.taskprojects.build(project: #project)
if #task.save
...
In your controller statement Project.find(params[:taskproject_id]), it looks like params[:taskproject_id] is nil. Looking at the code in your form view the params passed to the controller should be params[:id]. It's also not clear where task_params is defined
If you still are getting the error, check the params in the log output from when you submit your form and post them here.
Updated w/ dev log. See below
I'm using vanity urls in my routing and I"m assuming it has something to do with it...
In short my issue is I'm unable to have the user update their information. I can get the edit form to show up but on submit the update method doesn't run and I neither get a "fail" or "success".
The relevant routes look like this:
resources :users do
resources :friends
end
match '/:username/edit' => 'users#edit', :as => "edit_user"
match '/:username' => 'users#show', :as => "user"
My form looks like this now, but I've tried a couple different things.
<%= form_for #user, :url => user_path(#user.username) do |form| %>
<%= render 'shared/error_messages', :object => form.object %>
<div class="form">
<p> <%= form.label :description, "Message to friends" %> <br />
<%= form.text_area :description %> </p>
<%= form.submit "Update" %>
</div>
<% end %>
The edit and update controllers look like this:
def edit
#user = User.find_by_username(params[:username])
end
def update
#user = User.find(params[:id])
if #user.update_attributes(params[:user])
redirect_to user_url(current_user.username), :flash => { :success => "wham" }
else
redirect_to user_url(current_user.username), :error => { :error => "shiz" }
end
end
Currently, when the update form is submitting, you get directed to the users url but nothing happens. I'd appreciate any help. Thanks!
Update ----
I have changed my routes as described below using to_param. This works just fine but the problem still persists where my update form just redirects to the root_url. Under rake routes I get the correct path for update and the edit form is displaying correctly. Here is what I get form rake routes:
PUT /users/:id(.:format) {:controller=>"users", :action=>"update"}
And this is the dev log from submitting my form
Started POST "/1" for 127.0.0.1 at Wed Jan 05 16:09:54 -0500 2011
Processing by UsersController#show as HTML
Parameters: {"commit"=>"Update User", "authenticity_token"=>"OM1lIzizuFCYlxC3XmtmG/btqAsyjekHtqsiwlUDn3M=", "utf8"=>"✓", "username"=>"1", "user"=>{"description"=>"Update the message please"}}
User Load (0.2ms) SELECT "users".* FROM "users" WHERE ("users"."username" = '1') LIMIT 1
Redirected to http://0.0.0.0:3000/
ApplicationController::current_user
ApplicationController::current_user_session
User Load (0.2ms) SELECT "users".* FROM "users" WHERE ("users"."id" = 1) LIMIT 1
CACHE (0.0ms) SELECT "users".* FROM "users" WHERE ("users"."id" = 1) LIMIT 1
ApplicationController::current_user_session
Completed 302 Found in 44ms
Started GET "/" for 127.0.0.1 at Wed Jan 05 16:09:54 -0500 2011
Processing by PagesController#home as HTML
ApplicationController::current_user
ApplicationController::current_user_session
User Load (0.2ms) SELECT "users".* FROM "users" WHERE ("users"."id" = 1) LIMIT 1
CACHE (0.0ms) SELECT "users".* FROM "users" WHERE ("users"."id" = 1) LIMIT 1
ApplicationController::current_user_session
ApplicationController::current_user
ApplicationController::current_user
ApplicationController::current_user
ApplicationController::current_user
Rendered pages/home.html.erb within layouts/application (22.2ms)
Completed 200 OK in 61ms (Views: 32.4ms | ActiveRecord: 0.2ms)
Why does that redirect happen??
Rather than defining custom routes for this, just define the to_param method on the User class:
def to_param
username.parameterize
end
Then for your routes, the params[:id] value will be the username's paramertized version. For instance, mine would be ryan-bigg.
Even though your log doesn't indicate this is the case, I'd also check if the attr_accessible has :description added to it in User model. It's happened to me before - the form seems to work but information doesn't get stored.