Hi Rails group,
I understand the basic CRUD scaffold setup. I'm trying to figure out
the best way to implement the default index behavior with a model on
every page as navigation. I'm having a conflict implementing both
List.all and List.new on the same page.
For example, in create new, a basic call to the controller would
include:
<%= form_for @list do |form| %>
<label>name:
<p><%= form.text_field :name %></p>
</label>
<p><%= form.submit %></p>
<% end %>
The controller is:
def new
@list = List.new
end
The problem I have is how to also show the List.all on the same page.
The DEF index uses @lists = List.all for the function. I can't invoke
@list on the same page to both equal List.new and List.all.
Is the best practice to create a different method in the controller
(set it as a before_filter so I can show on all views) to show all?
I've created the following to test it out at in the controller:
before_filter :nav_show_lists
def nav_show_lists
respond_with(@nav_lists = List.all)
end
Then it is invoked in the application.html.erb view:
<% @nav_lists.each do |list| %>
<li><%= link_to "#{list.name}", list_url(list) %></li>
<% end %>
Thanks
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.