deegee wrote:
Hey Tom,
in your index, you have to pass the right variable to the partial,
like Fred wrote:
render :partial => ‘edit’, :user => u
u is the local variable you are passing (you called: for u in @users)
user is then the name of the variable you will use in your edit
partial (in Fred’s example, it was called ‘object’).
So in your partial, you need to do:
<% form_for user do %>
You can call it anything you want, but the symbol you use must match
the variable name you use in your partial. In your example, you’re
using ‘u’ but you never passed a variable called ‘u’ to the partial
(you passed ‘object’).
mhh, somehow im totally confused now. the index action /view iterates
through @users with an iterator called u:
Listing Users
Firstname |
Lastname |
Username |
<% for u in @users %>
<%=h u.firstname + u.id.to_s %> |
<%=h u.lastname %> |
<%=h u.username %> |
<%= link_to 'Show', u %> |
<%= render :partial =>'edit' , :@user => @users
%> |
<% end %>
///////////////////////////
user edit controller:
def edit
@user = User.find(params[:id])
end
means i have somehow to use that variable.
////////////////////////////////
partial:
Editing User
<% form_for(@user) do |f| %>
Title
<%= f.text_field :username %>
<%= f.submit "Update" %>
<% end %>
…summary: means i could replace
<%= render :partial =>‘edit’ , :@user => @users %>
with
<%= render :partial =>‘edit’ , :@whatever => u %> //u because of the
iterator
and use @whatever in the edit-display:
% form_for(whatever) do |f|
???
but that cant be true, where is the @users being used from the EDIT
action out of the controller?
i cant see thriough right now. help
thx