RAILS link_to external site, url is attribute of user table, like: @users.website
Looks like you need to stick the protocol on your link. E.g. you have www.userswebsite.com in your database, it should be http://www.userswebsite.com
Rails: Having a small issue with link_to and external URLs
Prepend url with protocol if it's absent:
module ApplicationHelper
def url_with_protocol(url)
/^http/i.match(url) ? url : "http://#{url}"
end
end
<%= link_to link.title, url_with_protocol(link.url) %>
answer derived from this SO question/answer
How do I defined a variable link_to to an external URL
It sounds like you are storing URLs without the http://
so they are being interpreted as relative URLs. You just need to do something like this:
link_to micropost.website, "http://#{micropost.website}"
or maybe add a full_url
method to that model that adds it if it's missing.
By the way, you can't use @micropost
in that partial because it doesn't exist (you only have @microposts
or micropost
).
Rails creating links to external sites with %= link_to %
Yes,
http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-link_to
<%= link_to 'facebook', 'https://www.facebook.com' %>
combine each do |f| with link_to controller action
<% @account.users.each do |f| %>
<ul> <h2><%= f.name %> |
<%= f.email %> |
<%= f.account_id %> </h2>
<%= link_to "Remove this user", user_path(f, :user => { :account_id => 0}),
:method => :put %> </ul>
<% end %>
@user will be current user and that is why it is updating current user
Preselecting an attribute in a form when creating new model in Rails
You can try passing the params to the new object in your controller, this should auto-populate the form:
def new
@regiser = Register.new(registered_at: params[:date]) #I don't know the column's name
end
how do add a link to an ActiveAdmin view
You can try:
row :foo do
link_to('foo','#')
end
and replace '#'
with your route.
How do I prevent images loaded from external websites/url's from slowing down my apps page loading times in ruby on rails?
This is because OpenGraph.fetch(url) launches an http request to get the necessary data to find the image tag. Since this has to occur during the render of your action, you can't send any information to the client until they all complete.
While there are many ways to deal with this, I would recommend creating a new action that given an opengraph identifier will return the opengraph data (basically put the helper method into the controller) and only output the identifier into the main action's view html. Then, in javascript, find all of those and execute an AJAX request to get the OpenGraph data and update the page's HTML once you have the response. This will allow the browser to execute the http requests in parallel while also not blocking the render of the page. For bonus points you can cache the OpenGraph responses in memcache or something with a reasonable expiration time and save the latency of having to HTTP request from your app each time.
Related Topics
Skip Over Iteration in Enumerable#Collect
Directory Layout for Pure Ruby Project
(Ruby,Rails) Context of Self in Modules and Libraries...
Class Method VS Constant in Ruby/Rails
Eager Loading: the Right Way to Do Things
Can Bundler Show Me Which Gems in Gemfile Have Newer Versions (Eg. Dry-Run of Bundle Update)
How to Use Correct Ruby in Vim? How to Modify $Path in Vim
Problem Signing Out with Devise on My App
Ruby Open-Uri Redirect Forbidden
Why Is Ruby Unable to Verify an Ssl Certificate
How Does Defining [Square Bracket] Method in Ruby Work
Find() with Nil When There Are No Records
How Mix in Routes in Sinatra for a Better Structure