hello all, I''m new to RoR. I am reading Agile Development etc. and I have completed a tutorial that explains the differences between rails 2.0 and rails 2.1. Still some questions are unanswered by the book. I hope you can help me with the most intriguing one: I have created a scaffold for model ''movie''. After some iterations I have manually added a admin controller with views. It appears that the image-links from the movie-view result in a get from the image in the directory public/images, whereas the image links from the admin views get the images another place. Can you explain WHY this happens and what I can do to p be able to - use public/images in both cases - use the same subdirectory of a view directory in both cases? thanks very much! Ruud --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Please can u paste the code in question and i will tell u, thanks. On Feb 26, 11:29 am, ruud <r.grosm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> hello all, > > I''m new to RoR. I am reading Agile Development etc. and I have > completed a tutorial that explains the differences between rails 2.0 > and rails 2.1. > > Still some questions are unanswered by the book. I hope you can help > me with the most intriguing one: > I have created a scaffold for model ''movie''. After some iterations I > have manually added a admin controller with views. > It appears that the image-links from the movie-view result in a get > from the image in the directory public/images, whereas the image links > from the admin views get the images another place. > > Can you explain WHY this happens and what I can do to p be able to > - use public/images in both cases > - use the same subdirectory of a view directory in both cases? > > thanks very much! > Ruud--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Rails by default will look into the public/images for any image name u give. If u have yr image in a separate folder like public/my_images folder then in yr view file u need to mention the image path as "my_images/image.jpg"> > Can you explain WHY this happens and what I can do to p be able to > - use public/images in both cases > - use the same subdirectory of a view directory in both cases? > > thanks very much! > Ruud-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
in fact, I don''t use the login_controller which uses the admin layout.
What''s in a name.
There is a difference between a list of the movies from the login view
and the movies view.
The admin layout includes the following lines:
<% if session[ :user_id ] %>
<% gebruiker = User.find_by_id( session[ :user_id]).naam -
%>
<h1><%= gebruiker -%></h1>
<%= link_to( ''overzicht films'', :action =>
''list_movies'' )
-%><br/>
<% else %>
<h1>no user</h1>
<% end %>
----------------------------------
In the login controller I have
def list_movies
@all_movies = Movie.find( :all)
@all_movies = [] if !@all_movies
end
-----------------------
and in the views/login list_movies.html.erb contains
<h1>Overzicht van films</h1>
<% if flash[ :notice ] %>
<div class=''flash''><%= flash[ :notice ]
-%></div>
<% end %>
<table>
<tr>
<th></th>
<th>beschrijving</th>
<th>acties</th>
</tr>
<% i = 0
for movie in @all_movies %>
<%= i += 1
(i % 2 == 0 ? ''<tr class="even">'' :
''<tr class="oneven">'') -%>
<td><img src="images/<%= movie.one_sheet_url
%>"/></td>
<td class=''titel''>
<b><%= movie.title %></b><br>
<%=h movie.description %>
</td>
<td>
<table>
<tr><td class=''actie''><%= link_to(
''toon'', {
:controller => ''movies'',
:action => ''show'',
:id => movie}) -%></td></
tr> <tr><td
class=''actie''><%= link_to
''bewerk'', edit_movie_path(movie) %></td></
tr>
<tr><td class=''actie''><%= link_to
''verwijder'', movie, :confirm =>
''Zeker weten?'',
:method => :delete
%></td></
tr>
</table>
</td>
</tr>
<% end %>
</table>
-----------------------------------
Following the link ''list users'' from the admin layout, I get a
table
in the browser, without the images displayed. Webrick says
http://localhost:3000/login/list_movies -> /login/images/shrekI.png
127.0.0.1 - - [26/Feb/2008:13:14:08 CET] "GET /login/images/
shrekII.png HTTP/1.1" 404 571
http://localhost:3000/login/list_movies -> /login/images/shrekII.png
127.0.0.1 - - [26/Feb/2008:13:14:09 CET] "GET /login/images/
shrekIII.png HTTP/1.1" 404 571
http://localhost:3000/login/list_movies -> /login/images/shrekIII.png
127.0.0.1 - - [26/Feb/2008:13:14:09 CET] "GET /login/images/BtoF.png
HTTP/1.1" 404 571
------------------
The images are in public/images, so that explains why they are not
displayed
Now, if I go to localhost:3000/movies, I get a listing of the movies
too;
movies/index.html.erb contains
<h1>Listing movies</h1>
<% if flash[ :notice ] %>
<div class=''flash''><%= flash[ :notice ]
-%></div>
<% end %>
<table>
<tr>
<th></th>
<th>beschrijving</th>
<th>acties</th>
</tr>
<% i = 0
for movie in @movies %>
<%= i += 1
(i % 2 == 0 ? ''<tr class="even">'' :
''<tr class="oneven">'') -%>
<td><img src="images/<%= movie.one_sheet_url
%>"/></td>
<td class=''titel''>
<b><%= movie.title %></b><br>
<%=h movie.description %>
</td>
<td>
<table>
<tr><td class=''actie''><%= link_to
''bewerk'',
edit_movie_path(movie) %></td></tr>
<tr><td class=''actie''><%= link_to
''verwijder'',
movie, :confirm => ''Zeker weten?'',
:method => :delete
%></td></
tr>
<tr><%= button_to( "doe in winkelmand", { :action
=> :add_to_cart,
:id => movie })
%></tr>
</table>
</td>
</tr>
<% end %>
</table>
<br />
<p><%= button_to( "leeg winkelmand", { :action =>
:empty_cart } ) -%></
p>
<%= link_to ''Nieuwe film'', new_movie_path() %>
--------------------------------
As you can see, it is almost the same as list_movies.html.erb.
But now, the images ARE displayed and webrick says
127.0.0.1 - - [26/Feb/2008:13:14:08 CET] "GET /login/images/shrekI.png
HTTP/1.1" 404 571
http://localhost:3000/login/list_movies -> /login/images/shrekI.png
127.0.0.1 - - [26/Feb/2008:13:14:08 CET] "GET /login/images/
shrekII.png HTTP/1.1" 404 571
http://localhost:3000/login/list_movies -> /login/images/shrekII.png
127.0.0.1 - - [26/Feb/2008:13:14:09 CET] "GET /login/images/
shrekIII.png HTTP/1.1" 404 571
http://localhost:3000/login/list_movies -> /login/images/shrekIII.png
I am puzzled. If you can shine a light on this I''d be very grateful.
Let me now if I have to provide extra information...
Ruud
--~--~---------~--~----~------------~-------~--~----~
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
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
I believe the issue is with the way you''re rendering the image tag.
This line:
<td><img src="images/<%= movie.one_sheet_url
%>"/></td>
Is a *relative path*. You should be able to use an absolute path "/
images/..." which will be absolute with respect to your Rails
application.
It''s probably also worth mentioning that, if you''re storing
images in
the standard /public/images folder, you can use a rails helper:
<td><%= image_tag move.one_sheet_url, :alt=>"#{movie.name}
pic" %></
td>
On Feb 26, 7:28 am, ruud
<r.grosm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> in fact, I don''t use the login_controller which uses the admin
layout.
> What''s in a name.
>
> There is a difference between a list of the movies from the login view
> and the movies view.
> The admin layout includes the following lines:
>
> <% if session[ :user_id ] %>
> <% gebruiker = User.find_by_id( session[ :user_id]).naam -
> %>
> <h1><%= gebruiker -%></h1>
> <%= link_to( ''overzicht films'', :action
=> ''list_movies'' )
> -%><br/>
> <% else %>
> <h1>no user</h1>
> <% end %>
> ----------------------------------
> In the login controller I have
>
> def list_movies
> @all_movies = Movie.find( :all)
> @all_movies = [] if !@all_movies
> end
> -----------------------
>
> and in the views/login list_movies.html.erb contains
>
> <h1>Overzicht van films</h1>
>
> <% if flash[ :notice ] %>
> <div class=''flash''><%= flash[ :notice ]
-%></div>
> <% end %>
> <table>
> <tr>
> <th></th>
> <th>beschrijving</th>
> <th>acties</th>
> </tr>
>
> <% i = 0
> for movie in @all_movies %>
> <%= i += 1
> (i % 2 == 0 ? ''<tr class="even">'' :
''<tr class="oneven">'') -%>
>
> <td><img src="images/<%= movie.one_sheet_url
%>"/></td>
> <td class=''titel''>
> <b><%= movie.title %></b><br>
> <%=h movie.description %>
> </td>
> <td>
> <table>
> <tr><td class=''actie''><%=
link_to( ''toon'', {
> :controller => ''movies'',
> :action => ''show'',
> :id => movie}) -%></td></
> tr> <tr><td
class=''actie''><%= link_to
> ''bewerk'', edit_movie_path(movie) %></td></
> tr>
> <tr><td class=''actie''><%= link_to
''verwijder'', movie, :confirm =>
> ''Zeker weten?'',
> :method => :delete
%></td></
> tr>
> </table>
> </td>
> </tr>
> <% end %>
> </table>
> -----------------------------------
>
> Following the link ''list users'' from the admin layout, I
get a table
> in the browser, without the images displayed. Webrick says
>
> http://localhost:3000/login/list_movies-> /login/images/shrekI.png
> 127.0.0.1 - - [26/Feb/2008:13:14:08 CET] "GET /login/images/
> shrekII.png HTTP/1.1" 404
571http://localhost:3000/login/list_movies-> /login/images/shrekII.png
> 127.0.0.1 - - [26/Feb/2008:13:14:09 CET] "GET /login/images/
> shrekIII.png HTTP/1.1" 404
571http://localhost:3000/login/list_movies-> /login/images/shrekIII.png
> 127.0.0.1 - - [26/Feb/2008:13:14:09 CET] "GET /login/images/BtoF.png
> HTTP/1.1" 404 571
> ------------------
>
> The images are in public/images, so that explains why they are not
> displayed
> Now, if I go to localhost:3000/movies, I get a listing of the movies
> too;
> movies/index.html.erb contains
>
> <h1>Listing movies</h1>
>
> <% if flash[ :notice ] %>
> <div class=''flash''><%= flash[ :notice ]
-%></div>
> <% end %>
> <table>
> <tr>
> <th></th>
> <th>beschrijving</th>
> <th>acties</th>
> </tr>
>
> <% i = 0
> for movie in @movies %>
> <%= i += 1
> (i % 2 == 0 ? ''<tr class="even">'' :
''<tr class="oneven">'') -%>
>
> <td><img src="images/<%= movie.one_sheet_url
%>"/></td>
> <td class=''titel''>
> <b><%= movie.title %></b><br>
> <%=h movie.description %>
> </td>
> <td>
> <table>
> <tr><td class=''actie''><%=
link_to ''bewerk'',
> edit_movie_path(movie) %></td></tr>
> <tr><td class=''actie''><%=
link_to ''verwijder'',
> movie, :confirm => ''Zeker weten?'',
> :method => :delete
%></td></
> tr>
> <tr><%= button_to( "doe in winkelmand", {
:action
> => :add_to_cart,
> :id => movie })
> %></tr>
> </table>
> </td>
> </tr>
> <% end %>
> </table>
>
> <br />
>
> <p><%= button_to( "leeg winkelmand", { :action =>
:empty_cart } ) -%></
> p>
> <%= link_to ''Nieuwe film'', new_movie_path() %>
> --------------------------------
>
> As you can see, it is almost the same as list_movies.html.erb.
> But now, the images ARE displayed and webrick says
>
> 127.0.0.1 - - [26/Feb/2008:13:14:08 CET] "GET /login/images/shrekI.png
> HTTP/1.1" 404 571http://localhost:3000/login/list_movies->
/login/images/shrekI.png
> 127.0.0.1 - - [26/Feb/2008:13:14:08 CET] "GET /login/images/
> shrekII.png HTTP/1.1" 404
571http://localhost:3000/login/list_movies-> /login/images/shrekII.png
> 127.0.0.1 - - [26/Feb/2008:13:14:09 CET] "GET /login/images/
> shrekIII.png HTTP/1.1" 404
571http://localhost:3000/login/list_movies-> /login/images/shrekIII.png
>
> I am puzzled. If you can shine a light on this I''d be very
grateful.
> Let me now if I have to provide extra information...
>
> Ruud
--~--~---------~--~----~------------~-------~--~----~
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
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
On 26 feb, 15:38, AndyV <a...-HmMyXyqgL2CVc3sceRu5cw@public.gmane.org> wrote:> I believe the issue is with the way you''re rendering the image tag. > This line: > > <td><img src="images/<%= movie.one_sheet_url %>"/></td> > > Is a *relative path*. You should be able to use an absolute path "/ > images/..." which will be absolute with respect to your Rails > application. >Yes, that is true. It IS relative. I am going to implement a helper function as you suggested. That is much better. But I still would like to know why movie.one_sheet_url() gives me another result when called from two different locations (in this case views/movies/index.html.erb and views/ and views/login/list_movies.html.erb) Rails has so much magic going on that a newbie like me gets a bit dizzy.> It''s probably also worth mentioning that, if you''re storing images in > the standard /public/images folder, you can use a rails helper: > > <td><%= image_tag move.one_sheet_url, :alt=>"#{movie.name} pic" %></ > td>Thanks, I wil certainly try this. Good opportunity to have a look at helper functions as well! Ruud --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 2/26/08, ruud <r.grosmann-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > > On 26 feb, 15:38, AndyV <a...-HmMyXyqgL2CVc3sceRu5cw@public.gmane.org> wrote: > > I believe the issue is with the way you''re rendering the image tag. > > This line: > > > > <td><img src="images/<%= movie.one_sheet_url %>"/></td> > > > > Is a *relative path*. You should be able to use an absolute path "/ > > images/..." which will be absolute with respect to your Rails > > application. > > > > > Yes, that is true. It IS relative. I am going to implement a helper > function as you suggested. That is much better. > But I still would like to know why movie.one_sheet_url() gives me > another result when called from two different locations > (in this case views/movies/index.html.erb and views/ and > views/login/list_movies.html.erb)Because it''s RELATIVE so if in one case it''s relative to views/movies, and in the other to views/login -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
+1... sorry I should have been more specific. On Feb 27, 8:31 am, "Rick DeNatale" <rick.denat...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 2/26/08, ruud <r.grosm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > On 26 feb, 15:38, AndyV <a...-HmMyXyqgL2CVc3sceRu5cw@public.gmane.org> wrote: > > > I believe the issue is with the way you''re rendering the image tag. > > > This line: > > > > <td><img src="images/<%= movie.one_sheet_url %>"/></td> > > > > Is a *relative path*. You should be able to use an absolute path "/ > > > images/..." which will be absolute with respect to your Rails > > > application. > > > Yes, that is true. It IS relative. I am going to implement a helper > > function as you suggested. That is much better. > > But I still would like to know why movie.one_sheet_url() gives me > > another result when called from two different locations > > (in this case views/movies/index.html.erb and views/ and > > views/login/list_movies.html.erb) > > Because it''s RELATIVE so if in one case it''s relative to views/movies, > and in the other to views/login > > -- > Rick DeNatale > > My blog on Rubyhttp://talklikeaduck.denhaven2.com/--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---