I don’t think the before_filter will work if you need
to have the action reflect the List.create step. What
about
def list_add
if List.create(params[:list])
index
render(:partial => “listform”)
end
?
Cheers,
B Gates
I am trying to follow the “DRY” principle and came
across a problem.
I am working on a small ajax task manager, and right
now in the index
page which renders the list, I have (for example, in
the Lists
controller):
You’re right; I hadn’t looked that carefully at your list_add function.
However, if what you’re trying to do is use ajax to add an item to a
task
list on a page, then you shouldn’t need to repopulate the your @lists
collection.
Instead your listform partial should contain the view for a single
record.
The index view would iterate through record set and show the partial for
each one.
def list_add
if List.create(params[:list])
render(:partial => “listform”)
end
end
Then in your index view, you have something like this:
<% for @list in @lists %>
<%= render(:partial => 'listform') %>
<% end %>
In _listform.rthml you then have the code that displays a single item
(which
you refer to as @list; ie, @list.title, etc.)
In fact, you can take it a step further and use RJS. Get rid of the
render
line in your list_add method. In the same folder as your index.rhtml,
create
a file called list_add.rjs. Your list_add method will automatically look
for
such a file and execute it if found. Add the following line to your
list_add.rjs file: