Add link at top bar in railsAdmin - ruby-on-rails

I'm using railsAdmin plugin in Rails4, now I want to add a new link on the top bar in railAdmin, on the right of Home link, can anybody tell me how to do that?

Modify /app/views/layouts/rails_admin/_secondary_navigation.html.haml
After %li= link_to t('admin.home.name'), main_app_root_path
You would do something to the effect of:
%li= link_to 'My Link', my_link_path
Assuming that you're linking to a path within your project, you can use $rake routes to figure out the correct route name.
If you're linking externally you would replace my_link_path with http://theurl.com

Related

Rails - HighVoltage - link anchor with title

I am using the High_Voltage gem to integrate static pages in my rails gem. I figured out how to link to anchors within a page (thanks to this previous answer. Now I also want to add a pop-up title to the links. I just randomly tried
link_to "About", page_path('indexpage', anchor: "aboutsection", title: "MyAboutTitle")
But this renders to
About
and, logically, does not produce the desired result.
Any suggestion? Thanks!
According to the Rail API for link_to to add html options, the title argument should be placed third in the method call, like this:
link_to "About", page_path('indexpage', anchor: "aboutsection"), title: "MyAboutTitle"
and it will output:
About

How to fix rails 4 hyperlinks?

I'm trying to display someone's profile links to their social media profiles. My current code is
<p>
<strong>Linkedin:</strong>
<%= link_to #person.linkedin, #person.linkedin %>
</p>
It works and the link does load, but it goes to localhost:3000/user/linkedin.com/in/user instead of linkedin.com/in/username
Thanks!
You need to add make sure the linkedin hyperlinks have a protocol (http, https, etc).
Any link without a protocol is assumed to be a relative path, which is why the hyperlinks are getting appended to your website url.
A solution would be to manually add a "http://" string at the beginning of every person's linkedin hyperlink in your database. Your code should work fine after that.
Edit: Or you can change it on the fly like so (the other answers won't work since it looks like #person.linkedin contains the entire hyperlink not just the linkedin user)
<%= link_to #person.linkedin, "https://#{#person.linkedin}" %>
Rails link helpers follow the format:
link_to(name = nil, options = nil, html_options = nil, &block)
The second #person.linkedin path is a local path as determined by your routes file in your config folder. If the link you need follows a certain format you can do something like
<%= link_to "LinkTextHere", "http://www.linkedin.com/#{#person}/profile" %>
I can answer in more detail if you give me the exact outcome you need as well as what you want from the .linkedin value. Also, typing "rake routes" in your console will show all paths you currently have and can help troubleshoot issues like why #person.linkedin is routing locally.

how to add link tag in ruby on rails

I need to display another page when I click the link. I am using the following code. But I didn't get the expected output. It says No route matches "/wel.html" with {:method=>:get} what can I do? Please help me.
<%= link_to "Click here", "wel.html" %>
ERB stands for "embedded Ruby", you can't have a link to an ERB file.
If you are pointing to an internal page, you should have a route to that through a controller action to make it actively reachable.
If you are pointing to an external source, you need to provide the full path, i.e. "http://...".
I'd suggest you take a look at a Rails tutorial before starting to build an app.
If you need to open wel.html file in your app, then you need to put it into public folder and change your link to <%= link_to "Click here", "/wel.html" %>.

Including a hash param in Rails URL

I have links on a page which go to pages_path('index').
That works fine, only I want each link to go to a specific section of a page.
So each link would look something like
www.example.com/pages/index#locations
Right now I'm using a rather hacky solution to generate this link
link_to "About", "#{page_path('index')}#about"
Is there a better way to achieve this?
You just need to use the anchor option:
link_to "About", page_path('index', anchor: "about")

What is the difference between link_to and link_to_unless_current?

I'm ust a beginner using Ruby on Rails for building website.. Here they have not clearly mentioned the difference between link_to and link_to_unless_current.
link_to will always generate a link.
link_to_unless_current will be ignored if the URL it would link to is the same as the URL that rendered the view containing it.
link_to just generates a link, link_to_unless_current only creates the link if the current page is not equal to the link you provided.
There is also a link_to_unless method, where you can provide a custom condition when to show the link.
For more information take a look at the UrlHelper documentation.
Link_to refers to "redirecting no matter what", and link_to_unless_current redirects unless it is already the current page.

Resources