Running RUby 1.9.3-p194 and Rails 3.2.3 and the latest paperclip gem.
I am following the tutorial here:
Multiple File Uploads with Paperclip & Rails 3 (Screencast)
I've set up a post to have multiple images. And I build 5 image objects in my controller.
However, this does not appear to show up in my view:
<% f.fields_for(:postimages) do |asset_fields| %>
<p><%= asset_fields.file_field :image %></p>
<% end %>
Any ideas on what I'm doing wrong?
Pretty sure you need an = on that first line, so
<%= f.fields_for(:postimages) ... %>
Related
I'm new to Ruby on Rails. I successfully implemented Active Storage to store files on my site. Now I'm trying to figure out how to display my attachments. I've mainly been following this documentation: (https://edgeguides.rubyonrails.org/active_storage_overview.html#displaying-images-videos-and-pdfs)
This is my code:
<% if #location.document.representable? %>
<%=image_tag #location.document.representation(resize_to_limit: [100, 100]) %>
<%="TRUE"%>
<% else %>
<%= link_to rails_blob_path(#location.document, disposition: "attachment") do %>
<%= image_tag "placeholder.png", alt: "Download document" %>
<%#"BROKEN"%>
<%="FALSE"%>
<% end %>
<% end %>
Currently, my problem is that the code generates the generic image not found image. I think the problem is '#location.document.representation' because most of the examples I've seen follow a variable.representation format (for example, document.represent). Most examples I found iterate through multiple attachments, but I only have document attached. The puzzling aspect is that it prints TRUE, meaning #location.document is representable. As I am a beginner, I know there is something I'm missing.
Update: I figured out the problem. If you scroll to the top of the documentation, you'll see you need to include this gem:
gem "image_processing", ">= 1.2"
The code itself was fine, it just needed to actually process the image to display.
I'm using Rails 5. I ahve the following image path
app/assets/images/loading_spinner.gif
I want to display this image on my page using the image_tag but neither
<% image_tag("images/loading_spinner.gif") %>
nor
<% image_tag("loading_spinner.gif") %>
displays any image tag on my page in my development environment. How do I fix this? I have tried restarting my server.
You are missing the equal:
<%= image_tag("loading_spinner.gif") %>
postI'm trying to retrieve related posts by tags by showing the attached image per related post, uploaded by using the carrierwave gem
Tags were written from scratch but similar to acts-as-taggable-on gem.
Below solution picked from Rails count article per tag and related article by tag displays the related posts by title.
<% #posts.each do |post| %>
<% post.tags.each do |tag| %>
RELATED POSTS:
<% tag.posts.each do |related_post| %>
<%= link_to related_post.title + " , ", post %>
<% end %>
<% end %>
<% end %>
Now I want related posts to be displayed by image instead of title per above. Code displaying image for post is
<%= image_tag(post.cover.url(:thumb)) if post.cover? %>
How can I fit this in the RELATED POSTS above?
I tried
<%= image_tag(related_post.cover.url(:thumb)) if post.cover? %>
but this throws:
NameError: undefined local variable or method 'related_post' for #<#:0x007fb67db38fb8>
Obviously related_post is not recorded in the carrierwave uploader model since it is different from the tags model. Any help please?
I understand Kaminari perform well with Rails3 reading this article: Rails 3 pagination, will_paginate vs. Kaminari, but how about with Rails4? Also, when stylizing them with Bootstrap3, which gem is easier solution?
In my experience, there is very little difference between Kaminari & Will Paginate - it's mainly a personal choice as to which you use (rather like Paperclip / Carrierwave or Mac / Windows)
In terms of compatibility, both gems work natively with Rails 4
Bootstrap
In reference to Bootstrap, I think you're asking the wrong question
Bootstrap is a CSS framework, which has no bearing on the backend functionality of your app
Bottom line is you're going to have to call the pagination methods from your controller, and so the differences of the systems will only be cosmetic. If you use Bootstrap to stylize them, you'll have to do the same with either gem
So the choice is yours!
It is pretty easy to implement twitter bootstrap pagination with Kaminari. Just follow the steps below:
Add gem 'kaminari' to your GemFile. Run bundle install and restart rails server
Check the Kaminary themes - in your case you need the bootstrap3 theme
Run rails g kaminari:views bootstrap3
That's it.
Kaminari works fine for me with Rails 4.1.5
You can get it working with Bootstrap 3 by changing one line of code in the generated Bootstrap theme for Kaminari
In Views/Kaminari/_paginator.html.erb
Change this line: <div class="pagination"><ul>
To this: <ul class="pagination pagination-lg">
..and get rid of the div; just use the ul above --works fine for me.
Here is the code for the whole partial:
<%= paginator.render do %>
<ul class="pagination pagination-lg">
<%= first_page_tag unless current_page.first? %>
<%= prev_page_tag unless current_page.first? %>
<% each_page do |page| %>
<% if page.left_outer? || page.right_outer? || page.inside_window? %>
<%= page_tag page %>
<% elsif !page.was_truncated? %>
<%= gap_tag %>
<% end %>
<% end %>
<%= next_page_tag unless current_page.last? %>
<%= last_page_tag unless current_page.last? %>
</ul>
<% end %>
First of all, I'm a Rails newbie. I can hold my own in Ruby, but Rails is a whole different story for me. I like the development speed Rails offers me, but I can't seem to make peace with the existing documentation.
For all of my forms so far, I used form_for, with an instance for the model I needed to create ( for example, submitting a new book ). I would really like to be able to just write something like :
<% form(:action => "whatever") %>
<% text_field ... %>
<% file_field ... %>
<% end %>
From the articles I read online, I understood that this was the way things got done in Rails < 2.0 . Is there anyway of doing this in Rails > 2.0, or something equivalent to it ? Can you please post a snippet ?
Take a look at form_tag.
<% form_tag '/posts' do %>
<div><%= submit_tag 'Save' %></div>
<% end %>