I'm trying to create a simple profile tab which includes a gravatar using Devise, however I keep getting an undefined methodemail' for nil:NilClass` cant' see where I'm going wrong
tab_check.html.erb
<div class="tabbable"> <!-- Only required for left/right tabs -->
<ul class="nav nav-tabs">
<li class="active">Dashboard</li>
<li>Inbox</li>
<li>Three</li>
<li>Four</li>
<li>Profile</li>
<li>Account</li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="tab1">
<p>This will be the Dashboard</p>
</div>
<div class="tab-pane" id="tab2">
<p>This will be the Inbox</p>
</div>
<div class="tab-pane" id="tab3">
<p>This will be tab 3</p>
</div>
<div class="tab-pane" id="tab4">
<p>This will be tab 4/p>
</div>
<div class="tab-pane" id="tab5">
<%= render 'users/show' %>
</div>
<div class="tab-pane" id="tab6">
<p>Account settings sections email etc</p>
</div>
</div>
</div>
users_controller.rb
class UsersController < ApplicationController
def index
#users = User.all
end
def show
#user = User.find(params[:id])
end
end
user.rb
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable,
# :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me,
:first_name, :last_name
# attr_accessible :title, :body
has_many :items
end
users_helper.rb
module UsersHelper
def gravatar_for(user, options = { size: 50})
gravatar_id = Digest::MD5::hexdigest(user.email.downcase)
size = options[:size]
gravatar_url = "http://gravatar.com/avatar/#{gravatar_id}.png?s=#{size}"
image_tag(gravatar_url, alt: user.name, class: "gravatar")
end
end
finally the _show.heml.erb
<div class="row">
<aside class="span4">
<section>
<h1>
<%= gravatar_for #user %>
<%= #user.first_name %>
</h1>
</section>
</aside>
</div>
EDIT: Full Stack trace:
app/helpers/users_helper.rb:3:in `gravatar_for'
app/views/users/_show.html.erb:5:in `_app_views_users__show_html_erb__248270508__620770878'
actionpack (3.2.3) lib/action_view/template.rb:143:in `block in render'
activesupport (3.2.3) lib/active_support/notifications.rb:125:in `instrument'
actionpack (3.2.3) lib/action_view/template.rb:141:in `render'
actionpack (3.2.3) lib/action_view/renderer/partial_renderer.rb:265:in `render_partial'
actionpack (3.2.3) lib/action_view/renderer/partial_renderer.rb:238:in `block in render'
actionpack (3.2.3) lib/action_view/renderer/abstract_renderer.rb:38:in `block in instrument'
activesupport (3.2.3) lib/active_support/notifications.rb:123:in `block in instrument'
activesupport (3.2.3) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (3.2.3) lib/active_support/notifications.rb:123:in `instrument'
actionpack (3.2.3) lib/action_view/renderer/abstract_renderer.rb:38:in `instrument'
actionpack (3.2.3) lib/action_view/renderer/partial_renderer.rb:237:in `render'
actionpack (3.2.3) lib/action_view/renderer/renderer.rb:41:in `render_partial'
actionpack (3.2.3) lib/action_view/helpers/rendering_helper.rb:27:in `render'
app/views/static_pages/tab_check.html.erb:25:in `_app_views_static_pages_tab_check_html_erb___410072822_92462190'
actionpack (3.2.3) lib/action_view/template.rb:143:in `block in render'
activesupport (3.2.3) lib/active_support/notifications.rb:125:in `instrument'
actionpack (3.2.3) lib/action_view/template.rb:141:in `render'
actionpack (3.2.3) lib/action_view/renderer/template_renderer.rb:47:in `block (2 levels) in render_template'
actionpack (3.2.3) lib/action_view/renderer/abstract_renderer.rb:38:in `block in instrument'
activesupport (3.2.3) lib/active_support/notifications.rb:123:in `block in instrument'
activesupport (3.2.3) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (3.2.3) lib/active_support/notifications.rb:123:in `instrument'
actionpack (3.2.3) lib/action_view/renderer/abstract_renderer.rb:38:in `instrument'
actionpack (3.2.3) lib/action_view/renderer/template_renderer.rb:46:in `block in render_template'
actionpack (3.2.3) lib/action_view/renderer/template_renderer.rb:54:in `render_with_layout'
actionpack (3.2.3) lib/action_view/renderer/template_renderer.rb:45:in `render_template'
actionpack (3.2.3) lib/action_view/renderer/template_renderer.rb:18:in `render'
actionpack (3.2.3) lib/action_view/renderer/renderer.rb:36:in `render_template'
actionpack (3.2.3) lib/action_view/renderer/renderer.rb:17:in `render'
actionpack (3.2.3) lib/abstract_controller/rendering.rb:110:in `_render_template'
actionpack (3.2.3) lib/action_controller/metal/streaming.rb:225:in `_render_template'
actionpack (3.2.3) lib/abstract_controller/rendering.rb:103:in `render_to_body'
actionpack (3.2.3) lib/action_controller/metal/renderers.rb:28:in `render_to_body'
actionpack (3.2.3) lib/action_controller/metal/compatibility.rb:50:in `render_to_body'
actionpack (3.2.3) lib/abstract_controller/rendering.rb:88:in `render'
actionpack (3.2.3) lib/action_controller/metal/rendering.rb:16:in `render'
actionpack (3.2.3) lib/action_controller/metal/instrumentation.rb:40:in `block (2 levels) in render'
activesupport (3.2.3) lib/active_support/core_ext/benchmark.rb:5:in `block in ms'
/home/toaksie/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/benchmark.rb:295:in `realtime'
activesupport (3.2.3) lib/active_support/core_ext/benchmark.rb:5:in `ms'
actionpack (3.2.3) lib/action_controller/metal/instrumentation.rb:40:in `block in render'
actionpack (3.2.3) lib/action_controller/metal/instrumentation.rb:83:in `cleanup_view_runtime'
activerecord (3.2.3) lib/active_record/railties/controller_runtime.rb:24:in `cleanup_view_runtime'
actionpack (3.2.3) lib/action_controller/metal/instrumentation.rb:39:in `render'
actionpack (3.2.3) lib/action_controller/metal/implicit_render.rb:10:in `default_render'
actionpack (3.2.3) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (3.2.3) lib/abstract_controller/base.rb:167:in `process_action'
actionpack (3.2.3) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (3.2.3) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (3.2.3) lib/active_support/callbacks.rb:414:in `_run__447462369__process_action__180978766__callbacks'
activesupport (3.2.3) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.3) lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks'
activesupport (3.2.3) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.3) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.2.3) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (3.2.3) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
activesupport (3.2.3) lib/active_support/notifications.rb:123:in `block in instrument'
activesupport (3.2.3) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (3.2.3) lib/active_support/notifications.rb:123:in `instrument'
actionpack (3.2.3) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.2.3) lib/action_controller/metal/params_wrapper.rb:205:in `process_action'
activerecord (3.2.3) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (3.2.3) lib/abstract_controller/base.rb:121:in `process'
actionpack (3.2.3) lib/abstract_controller/rendering.rb:45:in `process'
actionpack (3.2.3) lib/action_controller/metal.rb:203:in `dispatch'
actionpack (3.2.3) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.2.3) lib/action_controller/metal.rb:246:in `block in action'
actionpack (3.2.3) lib/action_dispatch/routing/route_set.rb:73:in `call'
actionpack (3.2.3) lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
actionpack (3.2.3) lib/action_dispatch/routing/route_set.rb:36:in `call'
journey (1.0.3) lib/journey/router.rb:68:in `block in call'
journey (1.0.3) lib/journey/router.rb:56:in `each'
journey (1.0.3) lib/journey/router.rb:56:in `call'
actionpack (3.2.3) lib/action_dispatch/routing/route_set.rb:600:in `call'
warden (1.1.1) lib/warden/manager.rb:35:in `block in call'
warden (1.1.1) lib/warden/manager.rb:34:in `catch'
warden (1.1.1) lib/warden/manager.rb:34:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
rack (1.4.1) lib/rack/etag.rb:23:in `call'
rack (1.4.1) lib/rack/conditionalget.rb:25:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/head.rb:14:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/flash.rb:242:in `call'
rack (1.4.1) lib/rack/session/abstract/id.rb:205:in `context'
rack (1.4.1) lib/rack/session/abstract/id.rb:200:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/cookies.rb:338:in `call'
activerecord (3.2.3) lib/active_record/query_cache.rb:64:in `call'
activerecord (3.2.3) lib/active_record/connection_adapters/abstract/connection_pool.rb:467:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (3.2.3) lib/active_support/callbacks.rb:405:in `_run__496782642__call__984513863__callbacks'
activesupport (3.2.3) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.3) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
activesupport (3.2.3) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.3) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/reloader.rb:65:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.3) lib/rails/rack/logger.rb:26:in `call_app'
railties (3.2.3) lib/rails/rack/logger.rb:16:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/request_id.rb:22:in `call'
rack (1.4.1) lib/rack/methodoverride.rb:21:in `call'
rack (1.4.1) lib/rack/runtime.rb:17:in `call'
activesupport (3.2.3) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.4.1) lib/rack/lock.rb:15:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/static.rb:62:in `call'
railties (3.2.3) lib/rails/engine.rb:479:in `call'
railties (3.2.3) lib/rails/application.rb:220:in `call'
rack (1.4.1) lib/rack/content_length.rb:14:in `call'
railties (3.2.3) lib/rails/rack/log_tailer.rb:14:in `call'
rack (1.4.1) lib/rack/handler/webrick.rb:59:in `service'
/home/toaksie/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
/home/toaksie/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
/home/toaksie/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'
Any pointers very much appreciated. Thanks
Your prbolem is that you render the show template in your tab_check.html.erb, but the user is not initialized. Your show action is not running if you use partial rendering on the show view, the user must be set in the tab_check action also.
Add #user = User.find(params[:id]) to your tab_check action.
Related
I have a word document that has a 4 level deep multilevel list. I would like to modify the list styles (temporarily) to show the entire depth of the numbers. For instance, rather than just showing (iii), I want to modify it to show 1.1(a)(iii). I have seen instructions of attaching the style to the list, but I'm not sure how to write the style to show what I want.
So, all of the searching and the replies have not resulted in a working solution, yet, but I did discover that the .docx file is a zipped collection of xml files. So, after looking inside the docx file and the numbering.xml sub-file, I found the following section that seems to define the style for the numbering I am looking to change:
<w:abstractNum w:abstractNumId="93" w15:restartNumberingAfterBreak="0">
<w:nsid w:val="5FE75E67"/>
<w:multiLevelType w:val="multilevel"/>
<w:tmpl w:val="9C366D9C"/>
<w:lvl w:ilvl="0">
<w:start w:val="1"/>
<w:numFmt w:val="decimal"/>
<w:pStyle w:val="ArticleCL1"/>
<w:lvlText w:val="%1"/>
<w:lvlJc w:val="left"/>
<w:pPr>
<w:tabs>
<w:tab w:val="num" w:pos="720"/>
</w:tabs>
<w:ind w:left="0" w:firstLine="0"/>
</w:pPr>
<w:rPr>
<w:rFonts w:ascii="Calibri" w:hAnsi="Calibri" w:cs="Times New Roman"/>
<w:b/>
<w:i w:val="0"/>
<w:caps/>
<w:smallCaps w:val="0"/>
<w:sz w:val="22"/>
<w:u w:val="none"/>
</w:rPr>
</w:lvl>
<w:lvl w:ilvl="1">
<w:start w:val="1"/>
<w:numFmt w:val="decimal"/>
<w:pStyle w:val="ArticleCL2"/>
<w:lvlText w:val="%1.%2"/>
<w:lvlJc w:val="left"/>
<w:pPr>
<w:tabs>
<w:tab w:val="num" w:pos="720"/>
</w:tabs>
<w:ind w:left="720" w:hanging="720"/>
</w:pPr>
<w:rPr>
<w:rFonts w:ascii="Calibri" w:hAnsi="Calibri" w:cs="Times New Roman"/>
<w:b w:val="0"/>
<w:i w:val="0"/>
<w:caps w:val="0"/>
<w:sz w:val="22"/>
<w:u w:val="none"/>
</w:rPr>
</w:lvl>
<w:lvl w:ilvl="2">
<w:start w:val="1"/>
<w:numFmt w:val="lowerLetter"/>
<w:pStyle w:val="ArticleCL3"/>
<w:lvlText w:val="(%3)"/>
<w:lvlJc w:val="left"/>
<w:pPr>
<w:tabs>
<w:tab w:val="num" w:pos="720"/>
</w:tabs>
<w:ind w:left="720" w:hanging="720"/>
</w:pPr>
<w:rPr>
<w:rFonts w:ascii="Calibri" w:hAnsi="Calibri" w:cs="Times New Roman"/>
<w:b w:val="0"/>
<w:i w:val="0"/>
<w:caps w:val="0"/>
<w:sz w:val="22"/>
<w:u w:val="none"/>
</w:rPr>
</w:lvl>
<w:lvl w:ilvl="3">
<w:start w:val="1"/>
<w:numFmt w:val="lowerRoman"/>
<w:pStyle w:val="ArticleCL4"/>
<w:lvlText w:val="(%4)"/>
<w:lvlJc w:val="left"/>
<w:pPr>
<w:tabs>
<w:tab w:val="num" w:pos="1440"/>
</w:tabs>
<w:ind w:left="1440" w:hanging="720"/>
</w:pPr>
<w:rPr>
<w:rFonts w:ascii="Calibri" w:hAnsi="Calibri" w:cs="Times New Roman"/>
<w:b w:val="0"/>
<w:i w:val="0"/>
<w:caps w:val="0"/>
<w:sz w:val="22"/>
<w:u w:val="none"/>
</w:rPr>
</w:lvl>
<w:lvl w:ilvl="4">
<w:start w:val="1"/>
<w:numFmt w:val="lowerLetter"/>
<w:pStyle w:val="ArticleCL5"/>
<w:lvlText w:val="%5."/>
<w:lvlJc w:val="left"/>
<w:pPr>
<w:tabs>
<w:tab w:val="num" w:pos="2160"/>
</w:tabs>
<w:ind w:left="2160" w:hanging="720"/>
</w:pPr>
<w:rPr>
<w:rFonts w:ascii="Calibri" w:hAnsi="Calibri" w:cs="Times New Roman"/>
<w:b w:val="0"/>
<w:i w:val="0"/>
<w:caps w:val="0"/>
<w:sz w:val="24"/>
<w:u w:val="none"/>
</w:rPr>
</w:lvl>
<w:lvl w:ilvl="5">
<w:start w:val="1"/>
<w:numFmt w:val="decimal"/>
<w:pStyle w:val="ArticleCL6"/>
<w:lvlText w:val="%6."/>
<w:lvlJc w:val="left"/>
<w:pPr>
<w:tabs>
<w:tab w:val="num" w:pos="2160"/>
</w:tabs>
<w:ind w:left="2160" w:hanging="720"/>
</w:pPr>
<w:rPr>
<w:rFonts w:ascii="Calibri" w:hAnsi="Calibri" w:cs="Times New Roman" w:hint="default"/>
<w:b w:val="0"/>
<w:i w:val="0"/>
<w:caps w:val="0"/>
<w:sz w:val="22"/>
<w:u w:val="none"/>
</w:rPr>
</w:lvl>
<w:lvl w:ilvl="6">
<w:start w:val="1"/>
<w:numFmt w:val="bullet"/>
<w:lvlRestart w:val="0"/>
<w:pStyle w:val="ArticleCL7"/>
<w:lvlText w:val="·"/>
<w:lvlJc w:val="left"/>
<w:pPr>
<w:tabs>
<w:tab w:val="num" w:pos="1440"/>
</w:tabs>
<w:ind w:left="1440" w:hanging="720"/>
</w:pPr>
<w:rPr>
<w:rFonts w:ascii="Symbol" w:hAnsi="Symbol" w:hint="default"/>
<w:b w:val="0"/>
<w:i w:val="0"/>
<w:caps w:val="0"/>
<w:sz w:val="24"/>
<w:u w:val="none"/>
</w:rPr>
</w:lvl>
<w:lvl w:ilvl="7">
<w:start w:val="1"/>
<w:numFmt w:val="bullet"/>
<w:lvlRestart w:val="0"/>
<w:pStyle w:val="ArticleCL8"/>
<w:lvlText w:val="·"/>
<w:lvlJc w:val="left"/>
<w:pPr>
<w:tabs>
<w:tab w:val="num" w:pos="2160"/>
</w:tabs>
<w:ind w:left="2160" w:hanging="720"/>
</w:pPr>
<w:rPr>
<w:rFonts w:ascii="Symbol" w:hAnsi="Symbol" w:hint="default"/>
<w:b w:val="0"/>
<w:i w:val="0"/>
<w:caps w:val="0"/>
<w:sz w:val="24"/>
<w:u w:val="none"/>
</w:rPr>
</w:lvl>
<w:lvl w:ilvl="8">
<w:start w:val="1"/>
<w:numFmt w:val="bullet"/>
<w:pStyle w:val="ArticleCL9"/>
<w:lvlText w:val="·"/>
<w:lvlJc w:val="left"/>
<w:pPr>
<w:tabs>
<w:tab w:val="num" w:pos="2880"/>
</w:tabs>
<w:ind w:left="2880" w:hanging="720"/>
</w:pPr>
<w:rPr>
<w:rFonts w:ascii="Symbol" w:hAnsi="Symbol" w:hint="default"/>
<w:b w:val="0"/>
<w:i w:val="0"/>
<w:caps w:val="0"/>
<w:color w:val="auto"/>
<w:sz w:val="24"/>
<w:u w:val="none"/>
</w:rPr>
</w:lvl>
Hopefully, this means that I can change the w:lvlText w:val="(%3) for w:ilvl="2" using VBA. Still investigating.
Thanks!
Rod
Well, it turns out that you can, indeed, directly modify a multiLevelList style at any level if you know how to refer to it. Using the xml file I referenced, I found that the third level style, ArticleC_L3, had it's number format set to "(%3)" which is what I wanted to change. It was in an abstract with AbstractNumId="93". The following code changes that setting:
wDoc.ListTemplates(94).ListLevels(3).NumberFormat = "%1.%2.%3"
You will notice that the ListTemplates number is one higher, and the ListLevels ID is likewise one higher. In either case, to find the precise place you need to refer to, the best workflow I have found is:
1. In the word doc, click on the number/bullet for the level you are trying to change.
2. Click the little dropdown arrow in the styles box so you can see what the style name is for that level.
3. Look in numbering.xml to see which number style is using that style name. For me the line read <w:pStyle w:val="ArticleCL3"/>
4. Follow the xml tree up to find out what level of the numbering style this is. For me the line read <w:lvl w:ilvl="2">
5. Continue to follow the xml tree up to find out what Template number the level is in. For me the line read <w:abstractNum w:abstractNumId="93" w15:restartNumberingAfterBreak="0">
6. Now you can refer to the exact level format as in the line I shared at the start.
Thanks for eveyone's help!
Rod
Presumably, something based on:
Sub ApplyMultiLevelStyleNumbers()
Dim LT As ListTemplate, i As Long
Set LT = ActiveDocument.ListTemplates.Add(OutlineNumbered:=True)
For i = 1 To 4
With LT.ListLevels(i)
.NumberFormat = Choose(i, "%1", "%1.%2", "%1.%2.%3", "%1.%2.%3.%4")
.Font.Bold = True
.ResetOnHigher = True
.StartAt = 1
.LinkedStyle = "ArticleC_L" & i
End With
Next
End Sub
The above assumes your four styles are named ArticleC_L1 - ArticleC_L4.
I've been working on this for a while and I managed to make this component work perfectly like this:
<h:form enctype="multipart/form-data">
<p:panelGrid columns="2">
<p:outputLabel value="Nombre:" for="nombre"/>
<p:inputText id="nombre" value="# {controladorProducto.producto.nombre}"/>
<p:outputLabel value="Descripción" for="descripcion"/>
<p:inputText id="descripcion" value="#{controladorProducto.producto.descripcion}"/>
<p:outputLabel value="Precio" for="precio"/>
<p:inputText id="precio" value="#{controladorProducto.producto.precio}"/>
<p:fileUpload id="fileuploader" value="#{controladorProducto.uploadedFile}"
mode="simple" />
<p:commandButton id="boton_cargar" value="Cargar" actionListener="#{controladorProducto.handleProductImageUpload}"
update="fotoProducto" ajax="true"/>
<p:outputLabel value="Imagen:" for="fotoProducto"/>
<p:graphicImage id="fotoProducto" value="#{controladorProducto.producto.imageToShow}"/>
<p:commandButton value="Insertar" action="#{controladorProducto.insertarProducto()}"/>
</p:panelGrid>
</h:form>
So as soon as I add any UI Component (you know, templates) it stops working. Here is the form with the template codes:
<ui:define name="top">
<h1>Buscador Clientes</h1>
<h:form id="form_growl">
<p:growl showDetail="false" />
</h:form>
</ui:define>
<ui:define name="left">
<h:form>
<p:menubar>
<p:menuitem value="Clientes" action="#{controladorCliente.buscarTodosClientes}" />
<p:separator/>
<p:menuitem value="Productos" action="#{controladorProducto.buscarTodosProductos}"/>
<p:separator/>
<p:menuitem value="Pedidos" url="#"/>
</p:menubar>
</h:form>
</ui:define>
<ui:define name ="content">
<h:form enctype="multipart/form-data">
<p:panelGrid columns="2">
<p:outputLabel value="Nombre:" for="nombre"/>
<p:inputText id="nombre" value="#{controladorProducto.producto.nombre}"/>
<p:outputLabel value="Descripción" for="descripcion"/>
<p:inputText id="descripcion" value="#{controladorProducto.producto.descripcion}"/>
<p:outputLabel value="Precio" for="precio"/>
<p:inputText id="precio" value="#{controladorProducto.producto.precio}"/>
<p:fileUpload id="fileuploader" value="#{controladorProducto.uploadedFile}"
mode="simple" />
<p:commandButton id="boton_cargar" value="Cargar" actionListener="#{controladorProducto.handleProductImageUpload}"
update="fotoProducto" ajax="true"/>
<p:outputLabel value="Imagen:" for="fotoProducto"/>
<p:graphicImage id="fotoProducto" value="#{controladorProducto.producto.imageToShow}"/>
<p:commandButton value="Insertar" action="#{controladorProducto.insertarProducto()}"/>
</p:panelGrid>
</h:form>
</ui:define>
</ui:composition>
Is there any problem, I've used the same template in other places of my project and it worked fine, its just here where it crashes. I get a NullPointerException and when i Debug it It didnt even call the bean.
At this point I´ve been looking around the Internet and I've not found anything.
Does anybody has any idea of why it doesnt works?
By the way, Im using NetBeans 7.3, GlassFish 3.1.2, Primefaces 3.5, JSF 2.1....
I hope someone answers me, I'd appreciate any help or clue on this.
This is the Error trace I get:
SEVERE: Se ha recibido 'java.lang.NullPointerException' al invocar la escucha de acción '#{controladorProducto.handleProductImageUpload}' para el componente 'boton_cargar'
SEVERE: java.lang.NullPointerException
at Controlador.ControladorProducto.handleProductImageUpload(ControladorProducto.java:59)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.sun.el.parser.AstValue.invoke(AstValue.java:254)
at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:302)
at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:153)
at javax.faces.event.ActionEvent.processListener(ActionEvent.java:88)
at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:769)
at javax.faces.component.UICommand.broadcast(UICommand.java:300)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1550)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:343)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:722)
SEVERE: JSF1073: se ha interceptado javax.faces.event.AbortProcessingException durante el procesamiento de INVOKE_APPLICATION 5 : UIComponent-ClientId=j_idt22:boton_cargar, Mensaje=java.lang.NullPointerException
SEVERE: java.lang.NullPointerException
javax.faces.event.AbortProcessingException: java.lang.NullPointerException
at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:182)
at javax.faces.event.ActionEvent.processListener(ActionEvent.java:88)
at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:769)
at javax.faces.component.UICommand.broadcast(UICommand.java:300)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1550)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:343)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.NullPointerException
at Controlador.ControladorProducto.handleProductImageUpload(ControladorProducto.java:59)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.sun.el.parser.AstValue.invoke(AstValue.java:254)
at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:302)
at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:153)
... 38 more
I am using CarrierWave to upload images to my server. However, when I reference them with image_url, I get a NoMethodError for nil:NilClass for image_url.
app/assets/views/albums/index.html.erb
<% #albums.each do |album| %>
....
<div>
<%= image_tag #album.image_url.to_s %>
</div>
<%end%>
app/config/routes.rb
namespace :admin do
root :to => "dashboard#index"
resources :dashboard
resources :albums do
resources :images
end
get "admin/album"
app/assets/views/albums/new.html.erb
<div>
<%= f.file_field :image %>
</div>
app/assets/models/Image.rb
class Image < ActiveRecord::Base
attr_accessible :album_id, :title, :image
belongs_to :album
mount_uploader :image, ImageUploader
end
image_uploader.rb
# encoding: utf-8
class ImageUploader < CarrierWave::Uploader::Base
# Include RMagick or MiniMagick support:
# include CarrierWave::RMagick
# include CarrierWave::MiniMagick
# Include the Sprockets helpers for Rails 3.1+ asset pipeline compatibility:
# include Sprockets::Helpers::RailsHelper
# include Sprockets::Helpers::IsolatedHelper
# Choose what kind of storage to use for this uploader:
storage :file
# storage :fog
# Override the directory where uploaded files will be stored.
# This is a sensible default for uploaders that are meant to be mounted:
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
# Provide a default URL as a default if there hasn't been a file uploaded:
# def default_url
# # For Rails 3.1+ asset pipeline compatibility:
# # asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
#
# "/images/fallback/" + [version_name, "default.png"].compact.join('_')
# end
# Process files as they are uploaded:
# process :scale => [200, 300]
#
# def scale(width, height)
# # do something
# end
# Create different versions of your uploaded files:
# version :thumb do
# process :scale => [50, 50]
# end
# Add a white list of extensions which are allowed to be uploaded.
# For images you might use something like this:
# def extension_white_list
# %w(jpg jpeg gif png)
# end
# Override the filename of the uploaded files:
# Avoid using model.id or version_name here, see uploader/store.rb for details.
# def filename
# "something.jpg" if original_filename
# end
end
I've been trying for hours to fix this error. I can get the error away by setting the image_tag path to image_url(#album), but this does not display the image.
MORE INFORMATION
app/views/admin/albums/index.html.erb:15:in `_app_views_admin_albums_index_html_erb__180744457_2201702940'
app/views/admin/albums/index.html.erb:3:in `each'
app/views/admin/albums/index.html.erb:3:in `_app_views_admin_albums_index_html_erb__180744457_2201702940'
actionpack (3.2.11) lib/action_view/template.rb:145:in `send'
actionpack (3.2.11) lib/action_view/template.rb:145:in `render'
activesupport (3.2.11) lib/active_support/notifications.rb:125:in `instrument'
actionpack (3.2.11) lib/action_view/template.rb:143:in `render'
actionpack (3.2.11) lib/action_view/renderer/template_renderer.rb:47:in `render_template'
actionpack (3.2.11) lib/action_view/renderer/abstract_renderer.rb:38:in `instrument'
activesupport (3.2.11) lib/active_support/notifications.rb:123:in `instrument'
activesupport (3.2.11) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (3.2.11) lib/active_support/notifications.rb:123:in `instrument'
actionpack (3.2.11) lib/action_view/renderer/abstract_renderer.rb:38:in `instrument'
actionpack (3.2.11) lib/action_view/renderer/template_renderer.rb:46:in `render_template'
actionpack (3.2.11) lib/action_view/renderer/template_renderer.rb:54:in `render_with_layout'
actionpack (3.2.11) lib/action_view/renderer/template_renderer.rb:45:in `render_template'
actionpack (3.2.11) lib/action_view/renderer/template_renderer.rb:18:in `render'
actionpack (3.2.11) lib/action_view/renderer/renderer.rb:36:in `render_template'
actionpack (3.2.11) lib/action_view/renderer/renderer.rb:17:in `render'
actionpack (3.2.11) lib/abstract_controller/rendering.rb:110:in `_render_template'
actionpack (3.2.11) lib/action_controller/metal/streaming.rb:225:in `_render_template'
actionpack (3.2.11) lib/abstract_controller/rendering.rb:103:in `render_to_body'
actionpack (3.2.11) lib/action_controller/metal/renderers.rb:28:in `render_to_body'
actionpack (3.2.11) lib/action_controller/metal/compatibility.rb:50:in `render_to_body'
actionpack (3.2.11) lib/abstract_controller/rendering.rb:88:in `render'
actionpack (3.2.11) lib/action_controller/metal/rendering.rb:16:in `render'
actionpack (3.2.11) lib/action_controller/metal/instrumentation.rb:40:in `render'
activesupport (3.2.11) lib/active_support/core_ext/benchmark.rb:5:in `ms'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/benchmark.rb:308:in `realtime'
activesupport (3.2.11) lib/active_support/core_ext/benchmark.rb:5:in `ms'
actionpack (3.2.11) lib/action_controller/metal/instrumentation.rb:40:in `render'
actionpack (3.2.11) lib/action_controller/metal/instrumentation.rb:83:in `cleanup_view_runtime'
activerecord (3.2.11) lib/active_record/railties/controller_runtime.rb:24:in `cleanup_view_runtime'
actionpack (3.2.11) lib/action_controller/metal/instrumentation.rb:39:in `render'
actionpack (3.2.11) lib/action_controller/metal/implicit_render.rb:10:in `default_render'
actionpack (3.2.11) lib/action_controller/metal/implicit_render.rb:5:in `send_action'
actionpack (3.2.11) lib/abstract_controller/base.rb:167:in `process_action'
actionpack (3.2.11) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (3.2.11) lib/abstract_controller/callbacks.rb:18:in `process_action'
activesupport (3.2.11) lib/active_support/callbacks.rb:425:in `_run__1857940186__process_action__440895155__callbacks'
activesupport (3.2.11) lib/active_support/callbacks.rb:405:in `send'
activesupport (3.2.11) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.11) lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks'
activesupport (3.2.11) lib/active_support/callbacks.rb:81:in `send'
activesupport (3.2.11) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.11) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.2.11) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (3.2.11) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
activesupport (3.2.11) lib/active_support/notifications.rb:123:in `instrument'
activesupport (3.2.11) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (3.2.11) lib/active_support/notifications.rb:123:in `instrument'
actionpack (3.2.11) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.2.11) lib/action_controller/metal/params_wrapper.rb:207:in `process_action'
activerecord (3.2.11) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (3.2.11) lib/abstract_controller/base.rb:121:in `process'
actionpack (3.2.11) lib/abstract_controller/rendering.rb:45:in `process'
actionpack (3.2.11) lib/action_controller/metal.rb:203:in `dispatch'
actionpack (3.2.11) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.2.11) lib/action_controller/metal.rb:246:in `action'
actionpack (3.2.11) lib/action_dispatch/routing/route_set.rb:73:in `call'
actionpack (3.2.11) lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
actionpack (3.2.11) lib/action_dispatch/routing/route_set.rb:36:in `call'
journey (1.0.4) lib/journey/router.rb:68:in `call'
journey (1.0.4) lib/journey/router.rb:56:in `each'
journey (1.0.4) lib/journey/router.rb:56:in `call'
actionpack (3.2.11) lib/action_dispatch/routing/route_set.rb:601:in `call'
actionpack (3.2.11) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
rack (1.4.5) lib/rack/etag.rb:23:in `call'
rack (1.4.5) lib/rack/conditionalget.rb:25:in `call'
actionpack (3.2.11) lib/action_dispatch/middleware/head.rb:14:in `call'
actionpack (3.2.11) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.2.11) lib/action_dispatch/middleware/flash.rb:242:in `call'
rack (1.4.5) lib/rack/session/abstract/id.rb:210:in `context'
rack (1.4.5) lib/rack/session/abstract/id.rb:205:in `call'
actionpack (3.2.11) lib/action_dispatch/middleware/cookies.rb:341:in `call'
activerecord (3.2.11) lib/active_record/query_cache.rb:64:in `call'
activerecord (3.2.11) lib/active_record/connection_adapters/abstract/connection_pool.rb:479:in `call'
actionpack (3.2.11) lib/action_dispatch/middleware/callbacks.rb:28:in `call'
activesupport (3.2.11) lib/active_support/callbacks.rb:405:in `_run__1915890415__call__4__callbacks'
activesupport (3.2.11) lib/active_support/callbacks.rb:405:in `send'
activesupport (3.2.11) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.11) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
activesupport (3.2.11) lib/active_support/callbacks.rb:81:in `send'
activesupport (3.2.11) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.11) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (3.2.11) lib/action_dispatch/middleware/reloader.rb:65:in `call'
actionpack (3.2.11) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
actionpack (3.2.11) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
actionpack (3.2.11) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.11) lib/rails/rack/logger.rb:32:in `call_app'
railties (3.2.11) lib/rails/rack/logger.rb:16:in `call'
activesupport (3.2.11) lib/active_support/tagged_logging.rb:22:in `tagged'
railties (3.2.11) lib/rails/rack/logger.rb:16:in `call'
actionpack (3.2.11) lib/action_dispatch/middleware/request_id.rb:22:in `call'
rack (1.4.5) lib/rack/methodoverride.rb:21:in `call'
rack (1.4.5) lib/rack/runtime.rb:17:in `call'
activesupport (3.2.11) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.4.5) lib/rack/lock.rb:15:in `call'
actionpack (3.2.11) lib/action_dispatch/middleware/static.rb:62:in `call'
railties (3.2.11) lib/rails/engine.rb:479:in `call'
railties (3.2.11) lib/rails/application.rb:223:in `call'
rack (1.4.5) lib/rack/content_length.rb:14:in `call'
railties (3.2.11) lib/rails/rack/log_tailer.rb:17:in `call'
rack (1.4.5) lib/rack/handler/webrick.rb:59:in `service'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/server.rb:162:in `start'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/server.rb:95:in `start'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/server.rb:92:in `each'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/server.rb:92:in `start'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/server.rb:23:in `start'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/server.rb:82:in `start'
rack (1.4.5) lib/rack/handler/webrick.rb:13:in `run'
rack (1.4.5) lib/rack/server.rb:268:in `start'
railties (3.2.11) lib/rails/commands/server.rb:70:in `start'
railties (3.2.11) lib/rails/commands.rb:55
railties (3.2.11) lib/rails/commands.rb:50:in `tap'
railties (3.2.11) lib/rails/commands.rb:50
script/rails:6:in `require'
script/rails:6
app/assets/views/albums/index.html.erb
<h1>These are the albums</h1>
<% #albums.each do |album| %>
<div class="item" style="background: #e4e4e4; border: 2px solid #c9c9c9; padding:1.5em 0 1.5em 0; width:17em; font-family: 'Signika Negative';">
<div class="title" style="background: #d3d3d3; display: inline-block; padding:1.5em 0 1.5em 1em; width: 12em;">
<strong>Title</strong> </br>
<%= album.title %></div>
</br>
<div class="description" style="background: #f9f9f9; display: inline-block; padding: 1.5em 0 1.5em 1em; width: 12em;">
<strong>Description</strong> </br>
<%= album.description %>
</div>
</br>
<div>
<%= image_tag album.image.image_url.to_s %>
</div>
<div>
</div>
<%= link_to "Delete", admin_album_path(album), :method => :delete, :style => "margin: 1em 0 0 1em; display: block;" %>
</br>
</div>
<% end %>
<%=link_to "New Album", :controller => "albums", :action => "new" %>
<%=link_to "Manage Pictures"%>
You seem to have a relation from albums to images. Assuming album has_many images you'll need:
#albums.each do |album|
album.images.each{|image| image.image_url }
end
Any ideas on how to get rid of this error.
Started GET "/favicon.ico" for 132.175.48.49 at 2012-12-18 11:20:59 +0000
ActionController::RoutingError (No route matches [GET] "/favicon.ico"):
actionpack (3.2.8) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.8) lib/rails/rack/logger.rb:26:in `call_app'
railties (3.2.8) lib/rails/rack/logger.rb:16:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/request_id.rb:22:in `call'
rack (1.4.1) lib/rack/methodoverride.rb:21:in `call'
rack (1.4.1) lib/rack/runtime.rb:17:in `call'
You probably have such a line (most likely in your application.html.erb, or some other template):
<link href="/favicon.ico" rel="shortcut icon" />
If you do, just change it to:
<link href="/assets/favicon.ico" rel="shortcut icon" />
I've been looking at examples of Muenchian grouping in XSLT 1.0, specifically this example here. However I'm unable to get it working on a more complex XML structure.
My XML currently looks like this:
<?xml version="1.0" encoding="utf-8"?>
<ContestResults>
<Contests>
<Contest sportId="35">
<Sport>Beach Volleyball</Sport>
<Event>Men's</Event>
<Ranks>
<Rank position="1" eventId="1">
<Athlete>Athlete 1a / Athlete 2a [GER]</Athlete>
<Result>2</Result>
</Rank>
<Rank position="2" eventId="1">
<Athlete>Athlete 1b / Athlete 2b [NED]</Athlete>
<Result>0</Result>
</Rank>
</Ranks>
</Contest>
<Contest sportId="32">
<Sport>Tennis</Sport>
<Event>Women's Singles</Event>
<Ranks>
<Rank position="1" eventId="2">
<Athlete>Tennis Athlete 1</Athlete>
<Result>2</Result>
</Rank>
<Rank position="2" eventId="2">
<Athlete>Tennis Athlete 2</Athlete>
<Result>1</Result>
</Rank>
</Ranks>
</Contest>
<Contest sportId="35">
<Sport>Beach Volleyball</Sport>
<Event>Men's</Event>
<Ranks>
<Rank position="1" eventId="3">
<Athlete>Athlete 3a / Athlete 4a [AUT]</Athlete>
<Result>2</Result>
</Rank>
<Rank position="2" eventId="3">
<Athlete>Athlete 3b / Athlete 4b [SUI]</Athlete>
<Result>0</Result>
</Rank>
</Ranks>
</Contest>
</Contests>
</ContestResults>
However I want to group the Rank nodes under the same Ranks parent when they have the same Sport and Event. So I want the result to look like this:
<?xml version="1.0" encoding="utf-8"?>
<ContestResults>
<Contests>
<Contest sportId="35">
<Sport>Beach Volleyball</Sport>
<Event>Men's</Event>
<Ranks>
<Rank position="1" eventId="1">
<Athlete>Athlete 1a / Athlete 2a [GER]</Athlete>
<Result>2</Result>
</Rank>
<Rank position="2" eventId="1">
<Athlete>Athlete 1b / Athlete 2b [NED]</Athlete>
<Result>0</Result>
</Rank>
<Rank position="1" eventId="3">
<Athlete>Athlete 3a / Athlete 4a [AUT]</Athlete>
<Result>2</Result>
</Rank>
<Rank position="2" eventId="3">
<Athlete>Athlete 3b / Athlete 4b [SUI]</Athlete>
<Result>0</Result>
</Rank>
</Ranks>
</Contest>
<Contest sportId="32">
<Sport>Tennis</Sport>
<Event>Women's Singles</Event>
<Ranks>
<Rank position="1" eventId="2">
<Athlete>Tennis Athlete 1</Athlete>
<Result>2</Result>
</Rank>
<Rank position="2" eventId="2">
<Athlete>Tennis Athlete 2</Athlete>
<Result>1</Result>
</Rank>
</Ranks>
</Contest>
</Contests>
</ContestResults>
I'm just a little lost how to do this as the only other examples are dealing with a much simpler structure and I'm not sure if it's possible or how my key and templates need to be structured to do this. Can anyone provide some examples how this might be achieved?
Any advice would be appreciated.
This transformation:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:key name="kContestById" match="Contest" use="#sportId"/>
<xsl:template match="node()|#*">
<xsl:copy>
<xsl:apply-templates select="node()|#*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Contests">
<Contests>
<xsl:apply-templates/>
</Contests>
</xsl:template>
<xsl:template match=
"Contest
[not(generate-id()
=
generate-id(key('kContestById', #sportId)[1]))
]"/>
<xsl:template match="Ranks">
<Ranks>
<xsl:apply-templates select="key('kContestById', ../#sportId)/Ranks/Rank"/>
</Ranks>
</xsl:template>
</xsl:stylesheet>
when applied on the provided XML document:
<ContestResults>
<Contests>
<Contest sportId="35">
<Sport>Beach Volleyball</Sport>
<Event>Men's</Event>
<Ranks>
<Rank position="1" eventId="1">
<Athlete>Athlete 1a / Athlete 2a [GER]</Athlete>
<Result>2</Result>
</Rank>
<Rank position="2" eventId="1">
<Athlete>Athlete 1b / Athlete 2b [NED]</Athlete>
<Result>0</Result>
</Rank>
</Ranks>
</Contest>
<Contest sportId="32">
<Sport>Tennis</Sport>
<Event>Women's Singles</Event>
<Ranks>
<Rank position="1" eventId="2">
<Athlete>Tennis Athlete 1</Athlete>
<Result>2</Result>
</Rank>
<Rank position="2" eventId="2">
<Athlete>Tennis Athlete 2</Athlete>
<Result>1</Result>
</Rank>
</Ranks>
</Contest>
<Contest sportId="35">
<Sport>Beach Volleyball</Sport>
<Event>Men's</Event>
<Ranks>
<Rank position="1" eventId="3">
<Athlete>Athlete 3a / Athlete 4a [AUT]</Athlete>
<Result>2</Result>
</Rank>
<Rank position="2" eventId="3">
<Athlete>Athlete 3b / Athlete 4b [SUI]</Athlete>
<Result>0</Result>
</Rank>
</Ranks>
</Contest>
</Contests>
</ContestResults>
produces the wanted, correct result:
<ContestResults>
<Contests>
<Contest sportId="35">
<Sport>Beach Volleyball</Sport>
<Event>Men's</Event>
<Ranks>
<Rank position="1" eventId="1">
<Athlete>Athlete 1a / Athlete 2a [GER]</Athlete>
<Result>2</Result>
</Rank>
<Rank position="2" eventId="1">
<Athlete>Athlete 1b / Athlete 2b [NED]</Athlete>
<Result>0</Result>
</Rank>
<Rank position="1" eventId="3">
<Athlete>Athlete 3a / Athlete 4a [AUT]</Athlete>
<Result>2</Result>
</Rank>
<Rank position="2" eventId="3">
<Athlete>Athlete 3b / Athlete 4b [SUI]</Athlete>
<Result>0</Result>
</Rank>
</Ranks>
</Contest>
<Contest sportId="32">
<Sport>Tennis</Sport>
<Event>Women's Singles</Event>
<Ranks>
<Rank position="1" eventId="2">
<Athlete>Tennis Athlete 1</Athlete>
<Result>2</Result>
</Rank>
<Rank position="2" eventId="2">
<Athlete>Tennis Athlete 2</Athlete>
<Result>1</Result>
</Rank>
</Ranks>
</Contest>
</Contests>
</ContestResults>
Explanation:
Proper use of the Muenchian grouping method and overriding the identity rule.