here is what I'm trying to do:
page.replace_html('manage_categories_list', :partial => "/categories/categories", :layout => :modal)
But, I get this error on the above code:
NoMethodError (undefined method `include?' for :modal:Symbol):
What I want to be able to do, is have template HTML for a modal dialog window. And set the header (h2) and the body (div) of that modal with any partial. =\
modal.html.erb:
<div class="fixed_modal">
<div class="modal_header">
<%= yield :header %>
</div>
<div class="modal_body">
<%= yield %>
</div>
</div>
The partial I'm trying to render:
<% content_for :header do %>
Manage Categories
<% end %>
.... rest doesn't matter as it just goes into the yield
I'm using rail 2.3.14
Most likely, you need to change it to ..., :layout => 'modal':
page.replace_html('manage_categories_list', :partial => "/categories/categories", :layout => :modal)
The #replace_html method accepts options like #render. For the :layout option, you either need to pass true, or a string layout file name (See the docs for #render).
The layout argument will be the 'xyz' part of the filename in app/views/layouts/xyz.html.erb.
The argument to :layout can't be a symbol try
:layout=>'modal'
This assumes you have a layout in app/views/layouts/modal.html.erb
Related
I have an app in which I different networks have messages.
In my network show view I display all the messages in with a partial "overview" which shows a link to the message content. The content of the messages is loaded with ajax inside #detailed div:
<div class="span2" id="sidebar">
<%= render :partial => 'shared/sidebar' %>
</div>
<div class="span4" id="overview">
<%= render :partial => 'overview' %>
</div>
<div class="span6" id="detailed">
<%= render :partial => 'nothing' %>
</div>
_overview.html.erb, in which i :
<h2>Messages</h2>
UNREAD:
<%= render :partial => 'items', :collection => #task.find_all{|item| item.unread == true }.sort_by(&:created_at).reverse, :as => :item %>
READ:
<%= render :partial => 'items', :collection => #task.find_all{|item| item.unread == false }.sort_by(&:created_at).reverse, :as => :item %>
_items.html.erb:
<%= div_for item do %>
<%= link_to(network_message_path(#network, item), :remote => true, :class => ["message item", ("unread" if item.unread == true)]) do %>...<% end %>
<% end %>
The message is contains a partial again with the full content, comments etc.. Code by which the message is loaded:
$("#detailed").hide().html("<%= j(render('show_message', :message => #message)) %>").fadeIn('fast');
If someone opens the detailed view, I update the unread status of the message to false. I would like to reload the overview partial, if someone loads the message into the details. One solution would be to just use jQuery to move things around, but the system will become more complicated with more filtering options. Therefor, reloading the overview partial would be a simpler solution. But what would be the fastes way to do so? As I need to reload the show method in the networks controller, alongside loading the show method in the message controller.
What would be the best solution, besides jQuery?
Created a module to load the overview partial with ajax.
I am using rails 3.1. I have a view products/show.html.erb and I call a partial like this
<%= render 'productrelationships/relatedproduct',:collection => #product.relatedproducts %>
and i access it in this way inside my partial (productrelationship/_relatedproduct)
<% logger.error 'Related Products ' + relatedproduct.inspect %>
The inspect returns a nil. But if I try the same inside my show.html.erb, it is not nil. There is some mistake in passing the value. What am I doing wrong?
Found the answer. It started working when i added :partial while rendering
<%= render :partial => 'productrelationships/relatedproduct',:collection => #product.relatedproducts %>
Need to specify the local variable.
<%= render :partial => 'productrelationships/relatedproduct',
:collection => #product.relatedproducts,
:as => :relatedproduct %>
I have a collection of partials being rendered using a layout for each element (wrapping in a container). However, when rendering the collection, an outer 'container' is also added (it appears to be adde to each render, despite no layout being specified.
Example:
# index.html.erb
<%= render :partial => 'sprockets' %>
# _sprockets.html.erb
<%= render :partial => 'sprocket', :layout => 'container' %>
<%= render :partial => 'sprocket', :layout => 'container' %>
<%= render :partial => 'sprocket', :layout => 'container' %>
# _sprocket.html.erb
...
# _container.html.erb
<div class="container"><%= yield %></div>
Gives:
<div class="sprocket">
<div class="sprocket">
...
</div>
<div class="sprocket">
...
</div>
<div class="sprocket">
...
</div>
</div>
I seem to remember being able to do this in Rails 2.3.8. Note the above is a simplification of my code (I'd like to keep the layouts and multi-partial format). Any ideas what I'm doing wrong? Thank!
You are probably exploiting a quirk in ActionView. To the best of my knowledge, layouts are not meant to be used with partials like that. My guess is, every time you do :layout => 'container', it sets the same instance variable. Since ActionView renders partials inside-out (innermost partial gets rendered first), the last used value for :layout also gets used higher up the chain.
Maybe doing something like
# index.html.erb
<%= render :partial => 'sprockets', :layout => false %>
will help.
Still I'd say this is not a proper way to get the results you want.
I have a loop in my view that renders many partials: each partial is a simple toggle to perform a save/unsave operation on a record. Each partial toggles the boolean field using javascript then updates itself, and the controller finishes by saying:
$ controller
render :partial => "save_unsave_buttons", :locals => {:matching => #matching}, :layout => false
# view
<div id=<%= "save#{match.id}" -%>>
<%= render :partial => "save_unsave_buttons", :locals => {:matching => match} %>
</div>
When the controller renders the save_unsave_buttons partial, it isn't rendering to the right div; it just updates the partial for the first record it finds. How can I ask the controller to render the save_unsave_buttons partial to the div with the right id?
Thanks!
Looking at only the little info that you provided for your problem i guess the culprit in the code is the div tag.
The div tag should be within the partial.
EDIT: What your code does is it creates a single div with id save(the first match.id) and renders the partial within it. If I understood you correctly you need a div for each match. For that the div itself should be within the partial.
So pass the match.id to the partial in a collection. Your view should be:
# view
<%= render :partial => "save_unsave_buttons", :locals => {:matching => match, :collection => {#match_id => match.id} } %>
and in your partial _sav_unsave_buttons.html.erb:
<% content_tag :div, id => "save#{#match_id}" do %>
#YOUR CODE GOES HERE!
<% end -%>
I am trying to create a tabbed interface using the prototype helper method "replace_html." I have three different partials I am working with. The first one is the 'main tab' and it is loaded automatically like so:
<div id = "grid">
<% things_today = things.find_things_today %>
<%= render :partial => "/todaything", :collection => things_today, :as =>:thing %>
</div>
...which works fine. Similarly, I have a _tomorrowthing partial which would replace the content in the 'grid' div like so:
<%things_tomorrow = things.find_things_tomorrow%>
<%= link_to_function('Tomorrow',nil, :id=>'tab') do |page|
page.replace_html 'grid' , :partial => '/tomorrowthing',:collection => things_tomorrow, :as => :thing
end %>
If I click on this tab nothing happens at all. Using firebug, the only errors I find are a missing ) after argument list which is contained in the Element.update block where the link_to_function is called. What am I doing wrong?
Hey Jack i try to reproduce the same but i can't i never used link_to_function before but
Following code may help to achieve the same you want
<%= link_to_remote "Today Thing", :url=>{:action=>"things", :id=>'today'}%>
<%= link_to_remote "Tomorrow Thing", :url=>{:action=>"things", :id=>'tomorrow'}%>
<div id = "grid">
<% #things = things.find_things_today %>
<%= render :partial => "/todaything", :collection => #things %>
</div>
in controller
def things
#things= (params[:id]=="today")? things.find_things_today : things.find_things_tomorrow
render :update do |page|
page.replace_html 'grid', :partial => (params[:id]=="today")? "/todaything" : '/tomorrowthing' , :objects=> #things
end