On Aug 22, 2013, at 5:29 PM, Nick Khamis <symack@gmail.com> 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@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
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.
No comments:
Post a Comment