views:

101

answers:

2

Hey all,

I have two problems with this code. First, regardless of what option I select from the dropdown menu, it does not update to database when clicking to submit form, yet when I refresh page, it updates the record of id 1. I basically just want to update the record that the user picks from dropdown menu. There's no associated model for this specific dropdown. @user_requests is the same model as :user_request, just with the records filtered by the site of the user. So the user only see records for their site. However, they still need to select an option and that option needs to be captured by params[:id], which it is currently not for some reason:

User Requests Controller:

def confirm   
x = current_user.contact.contactable
@user_requests = UserRequest.find(:all, :conditions => ["location_id = ?", x])
   if @user_request  = UserRequest.find(params[:id]) 
     update_confirm
    end
end

def update_confirm
@user_request.creator_id = current_user.contact.contactable
@user_request.save
end
end 

confirm.erb form:

<%  form_for(:user_request, :url => {:action => :confirm}) do %>
Request: collection_select(:user_request, :id, @user_requests, :id, :request_status_id) <br />
Password: <%= password_field_tag :password  %> <br />
<%= submit_tag 'Confirm Request' %>
<% end %>

routes: map.resources :user_requests, :member => {:confirm => :any}

For this part right here: if @user_request = UserRequest.find(params[:id]) I would like to capture the option the user selected. Any suggestions? Thanks.

+1  A: 

You probably need to change that to the following:

if @user_request = UserRequest.find(params[:user_request][:id])
mattwindwer
Yes, it worked. Why did it work? I thought you could perform finds with just id. Thanks.
JohnMerlino
+1  A: 

It works because you're usind the :id from the form_for statement, that came from a :user_request object.

collection_select(:user_request, :id, @user_requests, :id, :request_status_id)

returns '<'select id="user_request_id" name='user_request[id]''>'...

nanda