I'm trying to add images to my post which I thought that would be easier but god I've been struggling for a while now.
I tried to use Redcarpet and added some ruby Image_tag code but didn't work. Also I tried with tag and the raw method but no luck. I don't know I've been going around but I couldn't fine anything and I think I'm not asking nothing weird or complicated ahah.
Just add pictures from my /assets/images folder if is possible.
<%= img_tag ("my_photo.jpg")%>
How do you recommend to do it?
Many thanks
I use the image_tag helper and this has always worked fine for me. You could try this:
<%= image_tag("my_photo.jpg")%>
I figured it out. I used HTML tag instead of Ruby code.
<%= raw (#post.content) %>
As I am using assets pipeline:
<img src="/assets/my_photo.jpg" alt="twd" class="img-rounded"></img>
My issue was that I was calling my photo as /images/my_photo.jpg instead of /assets/my_photo.jpg... simple as that
Related
How can I call an image of some url external website using image_tag in a rails html view? Please, I'm looking for an alternative using image_tag not the regular html or css
EDIT Turns out OP wanted to do this b/c Heroku wasn't pulling in images from the assets folder. It is an issue that is easily resolved by reading/following the instructions here: Rails 4 images not loading on heroku .
Leaving the original answer here as it more correctly answers the original question.
image_tag works with full urls. So you could just give it the URL to the site you want to pull from. i.e:
<%= image_tag 'https://placekitten.com/800/400' %>
I'm sure you are already aware of this, but in 99.999% of situations, hot-linking images from other sites is a very bad idea.
Say you have an SVG file that is the image and it points to your Github or Linkedin profile, you could do something like this:
Setup:
In app/images/, you have some image file. For example, linkedin.svg.
Procedure
In your html.erb file, add:
<%= link_to image_tag("linkedin.svg"), "http://www.linkedin.com/in/myprofile", :target => "_blank"%>
Wait!!!!! READ CAREFULLY
Pay close attention to the space between image_tag and the parentheses(the method and the argument).
Some examples that you'll find online show a space between the image_tag and the argument. Keep them together.
Check the commas.
Last, just to be safe, make sure your link includes "http://www....."
I've just followed the install instructions at the the bootsy gem page and it all looks good until I save and look at the post's content.
This is what the output looks like in the view:
<h2>Header</h2><h3>Sub head:</h3><br><img alt="Thumb 1320236280147" src="/uploads/bootsy/image/1/1320236280147.jpg">
It seems that none of the html formatting is being rendered as it is being escaped by quoation marks or something like that - has anyone else had this problem? I haven't seen any issues on the github page or on SO to point me in the right direction.
I haven't done anything yet apart from follow the gem install instructions but maybe I missed something or am just making a stupid mistake.
If there's anything else you want to know please just ask.
Cheers
You need to have something like this, escape html:
<%= f.bootsy_area(:body, class: 'bg-code').html_safe %>
Sergio is correct but have the .html_safe on the output rather than the input.
For example, on a post index:
<%= post.body.html_safe %>
Hope this helps.
maybe use raw?
<%= raw(post.body) %>
You can also add to bootsy.rb
config.editor_options = {
html: true
.....
}
to enable you to toggle html in the bootsy editor .
Not sure how to fix this. should I be using .html_safe?
When the page renders I am getting a lot of:
<div><br><
which is obviously not what I am after.
Thanks.
Use CGI.unescapeHTML
<%= CGI.unescapeHTML(content) %>
I'm working on a Rails application and using HAML for the views. I would like to use the "sliding doors" technique to create pretty buttons, which means I need to get HAML to generate something similar to the following HTML:
<span class="button">Button text</span>
I haven't been able to figure out how to do that from the HAML reference or Google. Could you help please? Many thanks in advance.
EDIT: To clarify, I need to use the link_to helper because I'm linking to a resource. When I try to pass a block into the method, I get an error: undefined method 'stringify keys'
Try
= link_to invitation_path(invitation), :method=>:put, :class=>"button" do
%span(class="button")
Accept
This should be as simple as:
%a(href="#" class="button")
%span(class="button") Button text
Or if you especially want it on one line without any whitespace you can do:
%a(href="#" class="button")<
%span(class="button") Button text
I have the following issue. I have a google map (using YM4r + Geokit) within Ruby on Rails, anyhow, i basically have an array of markers which are populated in the following manner
#shops.each do
|sto|
markers << GMarker.new (....)
end
They are definitely being stored fine as under 10 markers they are displayed just fine. The problem arises when there are more than 10 markers on the same page,
Further code related to displaying if this may help:
#map.overlay_global_init(GMarkerGroup.new(true, markers), "sto_markers")
in the html.erb file:
<%= GMap.header %>
<%= javascript_include_tag("markerGroup") %>
<%= #map.to_html%>
<%= #map.div(:width => 700, :height => 500)%>
Only 10 markers are displayed on screen instead of the correct amount in the markers array.
Has anyone ever encountered this issue please? i'm really at a loss on how to overcome this please
Hmm, I have never used these plugins (I prefer to work directly with the API, much easier :)), so this is just random thinking.
Have you looked in the source of the rendered HTML? In there you should have a Javascript Object or Array with all your markers defined. If all of them do show up there, then it is easier to pinpoint if the problem is on the Javascript or the Rails side. (That is what <%= #map.to_html%> should do unless I'm completely off).
Update:
After some looking into the plugin, I can't really tell what the error can be, however since it do put out everything in clear Javascript in the file, it would probably help a lot if you can post the rendered HTML source. I believe that you will find the solution by looking there.