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
Related
I'm building a personal website using Ruby with Rails 4.
I'm attempting to scrape Medium.com and have my Medium articles show up on my page. It's almost working, they are displaying on my page how I would want them, but it also displays the entire RSS code underneath my blog posts. I can't figure out how to get this data dump off my view.
What can I do to change this?
Here is my code on the controller:
def blog
require 'rubygems'
require 'rss'
require 'open-uri'
#rss = RSS::Parser.parse('https://medium.com/feed/#AlextheYounger/')
end
Here is the code on my HTML view:
<%= #rss.items.each do |item|%>
<div class="row">
<div id="article-div" class="col-xs-8">
<div class= "well well-lg">
<div class= "article-title">
<p><%="#{item.title}"%></p>
</div>
</div>
</div>
</div>
<% end %>
Again, it actually does display my blog posts, it just does so with a massive data dump included. How do I get rid of this massive data dump?
The issue is that <%= differs from <%
The equals sign tells rails "spit out the result of the current ruby statement onto the screen into your html"... in this case, you are spitting out the result of the ruby-code: #rss.items.each... which happens to return the value of #rss.items (which is all of your rss feed).
For ruby-statements that don't need to output to the screen (like this), just change to using the non-equals-sign version: <% and you should be good to go.
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
Rails noob here. I'm attempting to create create single-page scrolling site similar to this ...but, you know, not nearly as attractive :-)
Anyway, I've got my javascript working however I've developed much of the content (contact form, about us page etc etc) in different views which are hanging out in various html.erb files. Rather than cut and paste the contents of each into a single home.html.erb, I was wondering if there was a clean way to just embed the content from each view into my homepage view. Something like this:
<h1>My awesome homepage!</h1>
<div>
<div id="about">
<%= put_page_here page=about_us %>
</div>
<div id="our_product">
<%= put_page_here page=about_us %>
</div>
<div id="contact">
<%= put_page_here page=contact %>
</div>
</div>
If you would recommend going about this entirely differently, please let me know.
Many thanks in advance!
This should work:
<%= render partial:"shared/contact_us", locals:{variable:value} %>
Note that it will look for a view in app/views/shared/_contact_us.html.erb - notice the _ before the view. Pass the variables the view needs in through locals. More information on passing variables around here.
I have my navigation menu in application.html and the menu has class="active" . That depends on the page the user is on. How can I dynamically figure out which item needs to have the class:
Here's how my top menu bar is:
<ul>
<li class="active">Home</li>
<li>Page1</li>
<li>Page2</li>
<li>Page3</li>
</ul>
One way would be to have an #active_page instance variable in the controllers, which you set on each action. You may also do this already with a title (#title maybe?), so perhaps you could use that instead. Then in the template:
<li class="<%= "active" if #active_page == "Home" %>">...</li>
The easiest (and possibly the most rudimentary) is to use current_page?. You can read up in the docs to see how it works. As I've experienced, it does not always produce what you want.
There is also a gem, navigasmic, which works pretty well if your needs get fairly complex.
There are a number of ways to accomplish what you are trying to do. Try out current_page? first and if you find yourself ripping your hair out, move on to something like navigasmic.
you can create a siple helper like this
def nav_link(name, url)
selected = url.all? { |key, value| params[key] == value }
link_to(name, url, :class => (selected ? "youarehere tabs" : "tabs"))
end
<div id="tabs" class="tabs2">
<%= nav_link %>
<%= nav_link %>
<%= nav_linl %>
</div>
then add the necessary css styles
Silly question and I hope I just overlooked this. In Sitefinity, once you are logged in, there is a wrapping div which one can use to target certain html tags ONLY when you are logged in.
I am not seeing anything like this in DNN and was wondering if someone knows of a solution to this please?
What I would like, is something like this:
[div class="dnn-logged-in"]
[div class="my-content-wrapper"]
[div class="elements-i-would-like-to-show-or-hide]
Hide or show this if I am logged in or not
[/div]
[/div]
[/div]
Many thanks!
I'd say this is a fairly uncommon task because this type of logic is generally handled on the server side and not the client side. This is because you generally don't want to increase the client payload any more than you need to - and if the user isn't logged in - they'll never need this content. In addition there are obviously security implications if working with sensitive data - as the information is easily viewable in the underlying markup.
All disclaimers aside, If you do want to do this, I think the best solution would be to just make site work just like you're used to in Sitefinity. In DNN you would create a container that contains the appropriate logic. A container wraps each module, and within the container you have the opportunity to write any code (server or client) to make your container dynamic.
For this brute force example I modified the "Invisible.ascx" container that ships with the DarkKnight skin in DNN 6:
<%# Control language="C#" AutoEventWireup="false" Inherits="DotNetNuke.UI.Containers.Container" %>
<%
var isLoggedIn = HttpContext.Current.User.Identity.IsAuthenticated;
if (isLoggedIn)
{
%>
<div class="dnn-logged-in">
<% } %>
<div class="Invisible"><div id="ContentPane" runat="server"></div></div>
<% if (isLoggedIn) { %>
</div>
<% } %>
This will yield the following HTML when not authenticated:
<div class="DnnModule DnnModule-DNN_HTML DnnModule-364">
<a name="364"></a>
<div class="Invisible">
<div id="dnn_ctr364_ContentPane">
[Dynamic Content Here]
</div>
</div>
</div>
and this when you are authenticated:
<div class="DnnModule DnnModule-DNN_HTML DnnModule-364">
<a name="364"></a>
<div class="dnn-logged-in">
<div class="Invisible">
<div id="dnn_ctr364_ContentPane">
[Dynamic Content Here]
</div>
</div>
</div>
</div>
If you want this logic everywhere, I'd just enhance each of the containers that you're currently using with this type of logic.
You can use SkinObject to do so in dnn. Login skin object will help you showing a Login/ Logout OR Regiter, User Skin object will help you show the currently logged in user. You can use any style and div you want.
In DotNetNuke this is controlled by permissions, which can be assigned to pages or to individual modules (specific content). By default, new pages will have VIEW permissions for "All Users", and new content created on the page will inherit that permission.
To change this, select the settings for the specific content, un-check the "Inherit View Permissions from Page. This will enable the check-boxes for all the various roles. Then simply ensure that All Users is un-selected, and instead select "Registered Users". This will make the content visibleto any user who is logged into the site.
This is a super powerful permission model which actually controls the rendering, rather than just obscuring visibility.