Page not working on Heroku - ruby-on-rails

I made an app in RoR and it's working perfectly locally, but there's only one page that's not working when I upload to Heroku. It's a view that has only this in the code:
<h1>Listagem</h1>
<% #items.each do |item| %>
<%= link_to item.materia, public_path(item) %>
<% end %>
<br />
I noticed that if I remove the public_path(item) the page works, so, is there any alternative to this?

THe only thing that sticks out to me is that you may have misspelled material in
<%= link_to item.materia, public_path(item) %>
this would throw an exception. You might want to check your logs as well

Related

rails ERB template language construct for <%= vs <% compared with django templates

coming from Django I am wondering how rails people think about <%= %> vs <% %>
From what I see here <%= tag.title %> displays information that's already present like attributes of the obj, like the {{ }} in django, and <% %> always does stuff, like an each loop or if statement, like the {% %} in django.
If that statement fully accurate, or is there a finer line I missed? Thanks
Yeah you've basically got it down.
<% %>
Will run ruby code without displaying it
<%= %>
Will display the information to the screen
<%# %>
Will comment out ruby code in your view
Here's just a simple example
<% #users.each do |user| %>
<%= user.email %>
<% end %>
This question may help you as well.

Displaying an image in erb that's hosted elsewhere online

I'm having a little trouble trying to display an image that is hosted on another site. Usually I would have the image in my assets pipeline, but on this project I am using an API to grab the image URL that's hosted on another site. I'm trying it this way below, but I feel like it's still pointing to my assets folder. How can I set it to display this image if it meets a conditional? Thanks!
...
<% if article.image_url %>
<%= image_url("<%= article.image_url %>") %><p>
<% end %>
...
Try <%= image_tag(article.image_url) if article.image_url %>
Hope this helps!
I believe you'd need to interpolate article.image_url like so:
<% if article.image_url %>
<%= image_tag article.image_url %><p>
<% end %>

Rails Carrierwave url is nil unless queried again

I am having an issue with carrierwave/active-record in my rails application. My problem is that the following code resolves all of the images to null
<% Ad.all.limit(30).each do |ad| %>
<img src="<%= ad.carrier_image.url %>" >
<% end %>
Where as the following renders all the images just fine
<% Ad.all.limit(30).each do |ad| %>
<img src="<%= Ad.find(ad.id).carrier_image.url %>" >
<% end %>
The urls are there, just on the initial loop the carrier_image does not seem to be preloaded into the active record objects I think this is an issue with my understanding of rails eager loading, but I am having trouble figuring out how one would avoid this issue
What happens when you use the rails image_tag helper? You're also missing the brackets off the url call as per the carrierwave documentation, but I don't think that's what's causing you drama.
<%= image_tag ad.carrier_image_url() %>
As a side note, you should really move the "Ad.all.limit(30)" out of your view if you wish to keep it all "railsy".

Caching doesn't work Rails 4.0

I'm following the 'Agile Web Development with Rails 4' book and I'm stuck at page 105 about the caching.
I have the following code in index.html.erb
<% if notice %>
<p id="notice"><%= notice %></p>
<% end %>
<h1>Your Pragmatic Catalog</h1>
<% cache ['store', Product.latest] do %>
<% #products.each do |product| %>
<% cache ['entry', product] do %>
<div class="entry">
<%= image_tag(product.image_url) %>
<h3><%= product.title %></h3>
<%= sanitize(product.description) %>
<div class="price_line">
<span class="price"><%= number_to_currency(product.price) %></span>
</div>
</div>
<% end %>
<% end %>
<% end %>
The first doubt is the following:
1) What does cache ['store', Product.latest] exactly do? It creates a cache, available from all StoreController actions, named "store" and associates the cache with the Product.latest: why should I do the last thing? Why do I need to associate my cache to a Product.latest?
Always at the same page the book says: "As far as verifying that this works, unfortunately there isn't much to see. If you go to that page, you should see nothing change, which in fact is the point! The best you can do is to make a change to the template anywhere inside the cache block without updating any product and verifying that you do not see that update because the cached version of the page has not been updated".
So I tried something like this:
<% cache ['store', Product.latest] do %>
"hello"
........
........
<% end %>
But I still get this update, the page shows me the "hello" string, why is it so? Shouldn't I see it?
P.S. Obviously I edited my config/environments/development.rb and restarted the server
Start your application on production mode and you will see that caching works.
What did you edited in development.rb? Please compare it to production.rb and copy-paste all caching configuration properties.
I had the same "problem", and I think what the book is saying is not correct. As far as I can tell, the reason why you see the changes on the website, even though caching is active, is that Rails 4 uses cache digests. For more information, check out:
http://blog.remarkablelabs.com/2012/12/russian-doll-caching-cache-digests-rails-4-countdown-to-2013
When you changed config.cache_classes to false, you just told Rails to not automatically regenerate views with each request. That's why you stopped seeing changes, it's not because "caching" was working correctly.

How do I get multiple paperclip uploads to display in the view?

I'm very new to programming and have followed this screencast at emersonlackey.com on adding multiple paperclip uploads for a record. It all works great but I can't figure out how to display the uploaded images in the records show page.
They display fine on the edit page using:
<%= f.fields_for :venuephotos do |photo| %>
<% unless photo.object.new_record? %>
<p>
<%= link_to image_tag(photo.object.venuephoto.url(:thumb)), photo.object.venuephoto.url(:original) %>
<%= photo.check_box :_destroy %>
</p>
<% end %>
<% end %>
I've used paperclip in other models but they are the standard each record only has one upload so the images display fine with <%= #model.photo.url %> type call but I cant figure out this other way.
Any help is much apprectiated!
You want to do something like this:
<% for asset in #post.assets %>
<%= link_to image_tag(asset.asset.url(:thumb)), asset.asset.url(:original) %>
<% end %>
as per the code that goes along with the screencast.
https://github.com/Emerson/Multiple-File-Uploads-with-Paperclip-and-Rails-3/blob/master/app/views/posts/show.html.erb

Resources