Run a page created in rails 4.1 from the tag (html) code that acontinuacion I detail, for every time I Click on the menu I double the url:
pages / pages / pages (so in doubles in the url):
<li >
<a href="/pages">
<span>Paginas</span>
</a>
</li>
As execute a page in rails 4.1 from the tag ?????
Use link helper
<%= link_to pages_path do %>
<span>Paginas</span>
<% end %>
Related
In my rails web app (based on the RoR tutorial by Michael Hartl) I have a user mailer which shoots out an activation email when someone signs up. There is an account_activation.*.erb for both HTML and text versions of the email. My account_activation.html.erb is
<h1>Web App</h1>
<p>Hi <%= #user.first_name %>,</p>
<p>Welcome to the Web App!</p>
<% if #user.student? %>
<p>
Once you have activated your account, you need to fill out the following information:
<ul>
...
</ul>
</p>
<% elsif #user.teacher? %>
<p>
You have been created as a teacher.
After activation, you will need to reset your password as it has been
randomly generated.
</p>
<% end %>
<p>Click on the link below to activate your account:</p>
<%= link_to "Activate", edit_account_activation_url(#user.activation_token,
email: #user.email) %>
What I'm wondering is: what the corresponding account_activation.text.erb would be since I have a conditional statement in the HTML?
You can still use interpolated Ruby in your .text.erb files - it's ERB that handles that, not HTML. Your template should look pretty much the same, just laid out for text without any HTML tags.
Since text file print all of your whitespace, you'll probably want to use <%- and -%> tags in some places, which respectively consume space before and after your interpolations. You'll also end up indenting less and not breaking things onto multiple lines, unless you use some tool to clean that up.
Web App
Hi <%= #user.first_name %>,
Welcome to the Web App!
<%- if #user.student? -%>
Once you have activated your account, you need to fill out the following information:
- One
- Two
<%- elsif #user.teacher? -%>
You have been created as a teacher. After activation, you will need to reset your password as it has been randomly generated.
<%- end -%>
Click on the link below to activate your account:
<%= link_to "Activate", edit_account_activation_url(#user.activation_token,
email: #user.email) %>
I would like to loop over a directory of .png icons and add them to a on a standalone page. I would also like to expose the file name of the .png under each one.
In a nutshell, this should become an automated feature to display all icons I'm currently using in my development environment so I can use this standalone page as an icon directory.
I'm very new to Ruby but my question first led to me this article but does not go far enough:
Iterate through every file in one directory
My (basic inline HTML), attempt so far:
<ul>
<% Dir.glob('/assets/css/img/png/*.png') do |icon| %>
<li> <%= "#{icon}" %> </li>
<% end %>
</ul>
Any help is hugely appreciated.
I'm not an expert so any improvements would be appreciated. I could only get the Ruby Dir.glob() to iterate by providing the absolute path to the directory. I'm using Rails 4.0.8. Here's what works for me:
<ul>
<% Dir.glob("#{Rails.root}/app/assets/images/*.png") do |icon| %>
<% icon_base = File.basename(icon) %>
<li><%= link_to icon_base, image_url(icon_base) %></li>
<% end %>
</ul>
This produces a list of hyperlinks to all PNG images in /assets/images.
You are giving an absolute path to Dir.glob so it will not be relative to your Rails project directory.
Try prepending the Rails root path to get a valid absolute path.
Dir.glob(Rails.root + "/assets... etc
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
In my ruby on rails application, I have a controller hiring and in the view tree hiring controller have one page new and I add another page called viewhiring also
and I have added two tabs in both hiring and new page i.e below:
<div id="nave">
<ul id="menu">
<li class="sub">View Hiring
</li>
<li class="sub">Hiring //new page that I call hiring
</li>
</ul>
</div>
And I want to redirect from Hiring page to 'View Hiring' page using anchor View Hiring but its not working.
kindly help me, waiting for reply.
Thanks.
Helpers
You should read up about Rails URL helpers - you shouldn't be using <a href=""> in your view files, you can use <% link_to %> instead (as pointed out by #deepti Kakade):
<%= link_to "Hiring", templates_path %>
You really need to use all the rails helpers (there are many more than just link_to) in place of your HTML because they firstly help you keep your code DRY, but secondly ensure you're keeping up with the latest Rails developments
One of the main benefits of using a framework such as Rails is that it gives you the ability to focus on creating an amazing system, rather than worrying about small coding complications
--
Routes
Secondly, you have to consider your routes
#config/routes.rb
resources :hiring #-> hiring_path / domain.com/hiring/index
Rails' routing uses a resourceful structure - meaning it allows you to build a set of routes around "resources" in your application. Simply, "resources" are your controllers; but they're really your individual data records:
In this sense, you should look at which path you're using, as it will correspond directly to your routes
Use link_to, it generates the anchor tag of html, for example
<%= link_to "linktext", action_path %>
your action_path is nothing but the href.
try this
<div id="nave">
<ul id="menu">
<li class="sub"> <%= link_to 'View Hiring', hiring_viewhiring_path %></li>
<li class="sub"><%= link_to 'Hiring', templates_path %></li> //new page that I call hiring
</ul>
</div>
Hope it helps .
'View Hiring'= is the name posted .
hiring_viewhiring_path = is the path
eg. welcome_index_path
this path is in \app/views/welcome/index.html
Did you get it ?
Hope this helps
link_to(body, url, html_options = {})
# url is a String; you can use URL helpers like
# posts_path
We are upgrading rails from 2.3.5 to 3.2.1. While upgrading we are getting issue with link_to method.We have the following code snippet.
link_to( name, path_options, html_options, *params )
Here name is:
<span class='bmark_link_tag'><img alt="Post this blog to Stumbleupon" src="/images/png/stumble.png" /> Stumbleupon</span>
But while rendering it is directly displaying the above name value instead of displaying image in UI.
Could you please help us on this ASAP.
You can use image_tag in link_to as,
<%= link_to image_tag("images/png/stumble.png", :alt=>"Post this blog to Stumbleupon", :class=>"bmark_link_tag")+"Stumbleupon", your_path %>
This is the code that I have for my posts/index.html.erb file:
<!--
Iterate over each post in list format
-->
<% #posts.each do |post| %>
<ul class="posts">
<!--
Link to article, display date created, show edit, delete links if logged in
-->
<li><%= link_to "#{post.title}".html_safe, post, id: "article" %></li>
<li id="date"> <%= post.created_at.strftime("%B %Y") %></li>
<% if logged_in? %>
<li>
<%= link_to 'Edit', "/editor" + post_path(post), id: "edit_delete", data: {save_url: mercury_update_post_path(post)} %>
<%= link_to 'Delete', post, id: "edit_delete", :method => :delete %>
</li>
<% end %>
</ul>
<% end %>
In my local development and production environments, the associated css stylesheet and html compiles and renders in the browser properly. BUT, when I deploy this code to heroku, it adds some old HTML that I had deleted earlier, as seen in the page source code:
<!--
Iterate over each post in list format
-->
<ul class="posts">
<!--
Link to article, display date created
-->
<li> <a href="/posts/5" id="article"><b>Endurance Exercise is Bad for your Health?</b>
<div><b><br></b></div></a> </li>
<li id="date"> February 2013 </li>
<!--
Show edit, delete links if logged in
-->
</ul>
see the <div><b><br></b></div> tags embedded within the link tag for the article "Endurance Exercise is Bad for your Health?" ... Anyone know why that is being put there when deployed to heroku on production?
This is your culprit. "#{post.title}".html_safe
One of the posts that you are displaying has html tags in its title. It's a bad idea to call .html_safe to anything entered by a user. You should escape that using h(post.title) or sanitize the string first for accepted tags. Look at the sanitize helper