Looking through the asset pipeline documentation, I was able to make everything work as expected. Really nice!! However, not for images that we are loading using a variable (i.e., wine.picture) which basically resolves to (bold_nine.jpg). First question, is it possible to use (asset_path) and pass variables? From the little bit of searching I found that (asset_path) does not support variables, and we should use (asset_url) instead. My concern is production env and the fingerprinting of images. Some observation: $(''#pic'').attr(''src'', "<%= asset_url(''block_nine.jpg'')%>") ------correctly yields-----> $(''#pic'').attr(''src'', "/assets/block_nine-b3cebc2ed66a8605caae943eacdd358d.jpg") $(''#pic'').attr(''src'', "<%= asset_url(''" + wine.pictures + "'')%>") ---------incorrectly yields-------> $(''#pic'').attr(''src'', "/" + wine. pictures + "") Error in console: ActionController::RoutingError (No route matches [GET] "/block_nine.jpg") That being said, $(''#pic'').attr(''src'', "<%= asset_url(''assets/" + wine.picture + "'')%>"); $(''#pic'').attr(''src'', "<%= asset_path(''assets/" + wine.picture + "'')%>"); both work in development and production however, I think at that point I am serving up the images from assets and not the web server using the fingerprints as intended. Your help is greatly appreciate, Nick. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/17d2a0d5-07df-4a76-8bed-048df49b4400%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
On Aug 8, 2013, at 2:08 PM, Nick Khamis <symack-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Looking through the asset pipeline documentation, I was able to make everything > work as expected. Really nice!! However, not for images that we are loading using > a variable (i.e., wine.picture) which basically resolves to (bold_nine.jpg). First > question, is it possible to use (asset_path) and pass variables? > > From the little bit of searching I found that (asset_path) does not support variables, > and we should use (asset_url) instead. My concern is production env and the fingerprinting > of images. Some observation: > > $(''#pic'').attr(''src'', "<%= asset_url(''block_nine.jpg'')%>") ------correctly yields-----> $(''#pic'').attr(''src'', "/assets/block_nine-b3cebc2ed66a8605caae943eacdd358d.jpg") > $(''#pic'').attr(''src'', "<%= asset_url(''" + wine.pictures + "'')%>") ---------incorrectly yields-------> $(''#pic'').attr(''src'', "/" + wine.pictures + "") >can''t tell for sure here - but it seems you might have the " and '' reversed in the above? you have the exterior quotes around the <%=..%> so you just need the string value produced by the asset_url, so try: $(''#pic'').attr(''src'', "<%= asset_url(wine.pictures)%>")> Error in console: > > ActionController::RoutingError (No route matches [GET] "/block_nine.jpg") > > That being said, > > $(''#pic'').attr(''src'', "<%= asset_url(''assets/" + wine.picture + "'')%>"); > $(''#pic'').attr(''src'', "<%= asset_path(''assets/" + wine.picture + "'')%>"); > > > both work in development and production however, I think at that point I am serving up the images from > assets and not the web server using the fingerprints as intended. > > Your help is greatly appreciate, > > Nick. > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/17d2a0d5-07df-4a76-8bed-048df49b4400%40googlegroups.com. > For more options, visit https://groups.google.com/groups/opt_out. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/6D7DCDFA-5D3C-4142-BAF1-DA98F63404B6%40gmail.com. For more options, visit https://groups.google.com/groups/opt_out.
Hello Tamouse, Thank you so much for your reply, Where trying $(''#pic'').attr(''src'', "<%= asset_path(wine.picture)%>");, I get the following error: undefined local variable or method `wine'' for #<#<Class:0x4231bdb0>:0x4311bb04> I hope I did not forget to mention that. wine.picture is a dynamic variable. Thanks in Advance, Nick. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/54568202-f908-4a36-80fa-9df16f42231b%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
On Aug 22, 2013, at 4:15 PM, Nick Khamis <symack-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hello Tamouse, > > Thank you so much for your reply, > > Where trying $(''#pic'').attr(''src'', "<%= asset_path(wine.picture)%>");, I get the following error: > > undefined local variable or method `wine'' for #<#<Class:0x4231bdb0>:0x4311bb04> > > I hope I did not forget to mention that. wine.picture is a dynamic variable.It appears that wine is not defined in the scope of that ERB call. How are you passing it to your view? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/A7C9779F-529E-4936-BD94-EF3FCE27F5E1%40gmail.com. For more options, visit https://groups.google.com/groups/opt_out.
Tamouse, I really appreciate this, and apologize for the partial code... `wine` is the parameter of a render function: function renderDetails(wine) { $(''#wineId'').val(wine.id); $(''#name'').val(wine.name); $(''#grapes'').val(wine.grapes); $(''#country'').val(wine.country); $(''#region'').val(wine.region); $(''#year'').val(wine.year); $(''#pic'').attr(''src'', wine.picture); $(''#description'').val(wine.description); } During runtime, the variable is filled with this JSON: 1. wine: Object 1. country: "France" 2. description: "The aromas of fruit and......" 3. grapes: "Grenache / Syrah" 4. id: 1 5. name: "CHATEAU DE SAINT COSME" 6. picture: "saint_cosme.jpg" 7. region: "Southern Rhone / Gigondas" 8. year: "2009" 2. PS I am new to Rails, so please forgive the noob :) Thanks in Advance, Nick. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/ca591adb-12da-433c-a2de-884b42de529c%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
On Aug 22, 2013, at 5:29 PM, Nick Khamis <symack-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> `wine` is the parameter of a render function: > > function renderDetails(wine) { > $(''#wineId'').val(wine.id); > $(''#name'').val(wine.name); > $(''#grapes'').val(wine.grapes); > $(''#country'').val(wine.country); > $(''#region'').val(wine.region); > $(''#year'').val(wine.year); > $(''#pic'').attr(''src'', wine.picture); > $(''#description'').val(wine.description); > } > > > During runtime, the variable is filled with this JSON: > > • wine: Object > • country: "France" > • description: "The aromas of fruit and......" > • grapes: "Grenache / Syrah" > • id: 1 > • name: "CHATEAU DE SAINT COSME" > • picture: "saint_cosme.jpg" > • region: "Southern Rhone / Gigondas" > • year: "2009" > • PS I am new to Rails, so please forgive the noob :) > Thanks in Advance,So wine is actually a Javascript object? From what I''m seeing above, it is in your Javascript, and you don''t have access to it inside an ERB call. So way back at the beginning, you were having trouble with this: $(''#pic'').attr(''src'', "<%= asset_url(''" + wine.pictures + "'')%>") when in fact, there shouldn''t have been any ERB stuff there at all: $(''#pic'').attr(''src'', wine.pictures) like you have in the above renderDetails function. It sounds now like you are setting that via an AJAX call. Where you need to look is in the controller that is responding to that AJAX call in your Rails application, and look how it is determining the value it will send for the picture source url. That is likely where you need to use asset_url (without any ERB stuff) to set that part of the JSON payload that gets returned to the client. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/B790A9EA-5D81-4B01-B886-CF3224E677B0%40gmail.com. For more options, visit https://groups.google.com/groups/opt_out.
Hello Tamouse,>> It sounds now like you are setting that via an AJAX call.This is correct. We are using JQuery to manage the payload.>> Where you need to look is in the controller that is responding to thatAJAX call in your Rails application,>> and look how it is determining the value it will send for the picturesource url. That is likely where you>> need to use asset_url (without any ERB stuff) to set that part of theJSON payload that gets returned>> to the client.I know this makes total sense, the problem is I am too new to Rails (not the case for C, C++ or Lisp) to understand :). The value for wine.picture url is coming straight from the database: +----+----------------------------------------------+------+----------------+---------------------------------------+ | id | name | year | country | picture | +----+----------------------------------------------+------+----------------+---------------------------------------+ | 1 | CHATEAU DE SAINT COSME | 2009 | France | saint_cosme.jpg | If I understand you correctly, I would need to modify the picture field in the database to read asset_url(''saint_cosme.jpg'') without any of the ERB stuff "<%= %>"? Or if by controller you mean rails controller in the traditional sense, I have a very simple `pages_controller.rb` that contains the following: class PagesController < ApplicationController def index end end As usual, forgive the noob, and thanks in advance!!! Nick. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/48648655-f787-43e6-9325-56797fdc86b7%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
On Aug 27, 2013, at 12:25 PM, Nick Khamis <symack-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hello Tamouse, > > > >> It sounds now like you are setting that via an AJAX call. > > This is correct. We are using JQuery to manage the payload. > > >> Where you need to look is in the controller that is responding to that AJAX call in your Rails application, > >> and look how it is determining the value it will send for the picture source url. That is likely where you > >> need to use asset_url (without any ERB stuff) to set that part of the JSON payload that gets returned > >> to the client. > > I know this makes total sense, the problem is I am too new to Rails (not the case for C, C++ or Lisp) to > understand :). The value for wine.picture url is coming straight from the database: > > +----+----------------------------------------------+------+----------------+---------------------------------------+ > | id | name | year | country | picture | > +----+----------------------------------------------+------+----------------+---------------------------------------+ > | 1 | CHATEAU DE SAINT COSME | 2009 | France | saint_cosme.jpg | > > If I understand you correctly, I would need to modify the picture field in the database to > read asset_url(''saint_cosme.jpg'') without any of the ERB stuff "<%= %>"?Do not modify the value in your database.> Or if by controller you mean rails controller in the traditional sense, I have a very simple > `pages_controller.rb` that contains the following:I mean the controller that is being called by your AJAX request. It is entirely possible this in not your Rails app, but I would think it would be. You have to look at your javascript and find the AJAX call, then look at the url in that call to find the route it''s seeking, and match that route to the controller. You can find out which routes map to controllers by running `rake routes`.> class PagesController < ApplicationController > def index > end > end > > As usual, forgive the noob, and thanks in advance!!! > > Nick.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/1D040D99-550A-4623-BC02-2B18DCEAF2F9%40gmail.com. For more options, visit https://groups.google.com/groups/opt_out.
On 29 August 2013 17:51, Tamara Temple <tamouse.lists-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > On Aug 27, 2013, at 12:25 PM, Nick Khamis <symack-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> Hello Tamouse, >> >> >> >> It sounds now like you are setting that via an AJAX call. >> >> This is correct. We are using JQuery to manage the payload. >> >> >> Where you need to look is in the controller that is responding to that AJAX call in your Rails application, >> >> and look how it is determining the value it will send for the picture source url. That is likely where you >> >> need to use asset_url (without any ERB stuff) to set that part of the JSON payload that gets returned >> >> to the client. >> >> I know this makes total sense, the problem is I am too new to Rails (not the case for C, C++ or Lisp) to >> understand :). The value for wine.picture url is coming straight from the database: >> >> +----+----------------------------------------------+------+----------------+---------------------------------------+ >> | id | name | year | country | picture | >> +----+----------------------------------------------+------+----------------+---------------------------------------+ >> | 1 | CHATEAU DE SAINT COSME | 2009 | France | saint_cosme.jpg | >> >> If I understand you correctly, I would need to modify the picture field in the database to >> read asset_url(''saint_cosme.jpg'') without any of the ERB stuff "<%= %>"? > > Do not modify the value in your database. > >> Or if by controller you mean rails controller in the traditional sense, I have a very simple >> `pages_controller.rb` that contains the following: > > I mean the controller that is being called by your AJAX request. It is entirely possible this in not your Rails app, but I would think it would be. You have to look at your javascript and find the AJAX call, then look at the url in that call to find the route it''s seeking, and match that route to the controller. You can find out which routes map to controllers by running `rake routes`.Also you can look in log/development.log to see what, if any, action is being called in the rails app when you perform the action. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLukFSEqV96d9e78z7L3JLX_jNaYP6frEUVuPbeR-07Lhg%40mail.gmail.com. For more options, visit https://groups.google.com/groups/opt_out.
Hello Guys, Sorry for the delayed response, I had to focus my effort elsewhere however, really need to figure (no pun intended) this out now. When looking into development.log, I see the following error: I, [2013-09-30T22:16:11.213141 #12076] INFO -- : Started GET "/pages/index" for 127.0.0.1 at 2013-09-30 22:16:11 -0400 I, [2013-09-30T22:16:11.221511 #12076] INFO -- : Processing by PagesController#index as HTML I, [2013-09-30T22:16:11.226746 #12076] INFO -- : Rendered pages/index.html.erb (0.6ms) I, [2013-09-30T22:16:11.229833 #12076] INFO -- : Completed 200 OK in 5ms (Views: 4.2ms | ActiveRecord: 0.0ms) I, [2013-09-30T22:16:12.990109 #12076] INFO -- : Started GET "/block_nine.jpg" for 127.0.0.1 at 2013-09-30 22:16:12 -0400 F, [2013-09-30T22:16:12.995561 #12076] FATAL -- : ActionController::RoutingError (No route matches [GET] "/block_nine.jpg"): Which is understandable since the file in the webserver is: block_nine-dbda8c968180776a036973cf045baba1.jpg The controller is not taking into consideration the fingerprint added by the precompile process. Please help! Thanks in Advance, Nick. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/dc10ba0b-15a9-4b57-b468-a5638cb1ef82%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.