I'm new to Rails and I'm trying to decipher how to link an image to open a different image (thumbnail vs large image, and they aren't the same).
I've tried:
<%= link_to "fullNews.jpg" do %>
<% image_tag("smallNews.jpg", :alt => "Newsletter Preview", class: "grow shadow") %>
<% end %>
As well as trying to use erb inside of erb:
<%= link_to "<% image_tag("fullNews.jpg") %>" do %>
<% image_tag("smallNews.jpg", :alt => "Newsletter Preview", class: "grow shadow") %>
<% end %>
Even a direct link:
<%= link_to "assets/images/fullNews.jpg" do %>
<% image_tag("smallNews.jpg", :alt => "Newsletter Preview", class: "grow shadow") %>
<% end %>
I'm sure it's just a syntax thing but I can't figure out how to achieve this?
Pretty easy:
<%= link_to image_url("fullNews.jpg") do %>
<%= image_tag("smallNews.jpg", :alt => "Newsletter Preview", class: "grow shadow") %>
<% end %>
Related
I am trying to use link_to syntax on this line but nothing working out.
How can I do that in ruby on rails?
<%= image_tag post.picture.url if post.picture? %>
Use link_to do block
<%= link_to root_path do %>
<%= image_tag post.picture.url if post.picture? %>
<%= end %>
Try below code:
<% if post.picture? %>
<%= link_to "/path" do %>
<%= image_tag post.picture.url %>
<%= end %>
<% end %>
Try below
<%= link_to image_tag post.picture.url, navigate_to_path if post.picture? %>
OR
You can also try below if you need a block for additional things along with an image.
<%= link_to navigate_to_path do %>
<%= image_tag post.picture.url %>
<% end if post.picture? %>
Hope this helps.
Actually this is my view am getting values from mysql database and i showed in browser based on the params page=1 page =2 page =3 and i want to change the params[:page] in form next button click.
Based on pages=1,2,3 questions and answers will vary thats why i need url to be change while button click in same page.! like below URL http://localhost:3000/responses/new?page=1 Thanks in advance.
<%= form_for (#response) do |f| %>
<% #questions.each do |pgquestion| %>
<% if pgquestion.group_id == 0 %>
<%= label :pgquest,pgquestion.description %><br><br>
<% else %>
<%= label :pgquest,pgquestion.description %>
<% (1..pgquestion.question_value.to_i).each do |i| %>
<%= radio_button_tag "ans_value[#{ pgquestion.quest_id }]", i %>
<% end %>
<br><br>
<% if pgquestion.question_type == "textarea" %>
<%= text_area "", "ans_value[#{ pgquestion.quest_id }]" ,size: '80x5' %><br><br>
<% else if pgquestion.question_type == "text" %>
<%= text_field "", "ans_value[#{ pgquestion.quest_id }]" %> <br><br>
<% end %>
<% end %>
<% end %>
<% end %>
<div style="text-align: center">
<%= f.submit 'Prev' ,:class => 'btn btn-primary',:name => "previous_button" %>
<%= f.submit 'Next', :class => 'btn btn-primary' %> <br><br>
<p><%= f.submit "Continue" %></p>
<p><%= f.submit "Back", :name => "previous_button" %></p>
</div>
<% end %>
As far as i understand your problem use the will_paginate gem https://github.com/mislav/will_paginate
I am trying to create a btn (using css) that will have both an image and a text.
I have the following code that works without the class, but when I am adding the class my code breaks. Is there a way to combine all of the above in link_to?
<%= link_to new_task_path do %>
<%= image_tag("new.png"), :class => 'btn btn-info' %> New Task
<% end %>
Solved with
<%= link_to image_tag("new.png") + "New Task" , new_task_path , :class => 'icon btn' %>
add the class on tag(anchor tag)
<%= link_to new_task_path, :class => 'btn btn-info' do %>
<%= image_tag("new.png") %> New Task
<% end %>
I'm trying to make link_to function have a css class attached to it,
My code is something like this:
<%= link_to newGame do%>
<%= image_tag newGame.image_url.to_s %>
<% end %>
which links an image to its content, but I need to add a class="thumbnail" to the link,
ie:
<a href="/games/:id" class="thumbnaill>
instead of what its currently generating:
<a href="/games/:id">
Thanks
Ref link_to
<%= link_to newGame, class: 'thumbnail' do %>
Be careful when using the older argument style, as an extra literal hash is needed:
<%= link_to "Articles", { :controller => "articles" }, :id => "news", :class => "article" %>
#Gives Articles
You can just do
<%= link_to newGame, class: 'thumbnail' do %>
<%= image_tag newGame.image_url.to_s %>
<% end %>
I'm trying to pass a link_to block with html but can't get it. I tried some other ways with no luck so I will use my original code:
<% link_to survey_path(survey), :class => "button" do %>
<span>add questions to <%= survey.name %></span>
<% end %>
This doesn't show the :class though.
What needs to be corrected?
Try to add = to make it <%= %>
<%= link_to survey_path(survey), :class => "button" do %>
<span>add questions to <%= survey.name %></span>
<% end %>
In the view code in Rails 3 applications it’s sometimes necessary to
use <%= instead of <% at the beginning of blocks that output content,
such as form_for.
Since it's just a span, why don't you just do
<%= link_to "add questions to #{survey.name}", survey_path(survey), :class => "button" %>