I'm trying to set up a mail-to-friend function from my Home Page so when the user clicks the email image their client opens up and has the title and message body already filled in. Any help would be appreciated?
<%= link_to image_tag("facebook.png"), "http://www.facebook.com/site" %>
<%= link_to image_tag ("twitter.png"), "http://twitter.com/#!/site" %>
<%= link_to image_tag "email.png" ???? %>
Here is the best way to achieve this according to the Rails api:
mail_to "me#domain.com"
# => me#domain.com
Full documentation at: http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-mail_to
Use a mailto tag
http://www.w3schools.com/html/tryit.asp?filename=tryhtml_mailto
Syntax here: http://www.ianr.unl.edu/internet/mailto.html
Related
I have an action which sends info to the serve through a POST method and I want it to be trigger from an email through a link.
I'v tried this in my email template:
First, specify the post method in a link_to tag:
<%= link_to 'click here', action_url(:id => #model.id), :method => 'post' %>
but the action is triggered with a GET method and I get a routing error.
And second, do it through a form with a hidden field but the csrf token was not recognized:
<%= form_tag action_url, :method => 'post' do %>
<%= hidden_field_tag :id, #model.id %>
<%= submit_tag 'click here' %>
<% end %>
Is there anyway to do this? Or if there isn't, what's my best option?
Couldn't make the post request, so just add the get route for the action.
Positive part: Worked fine, not complications
Negative part: Had to implement some before_filter methods for security due the parameters were passed through the URL
I am attempting to use resources to auto generate routes for my resource. The namespace is admin and the resource is author. The following code seems to work for most instances.
namespace :admin do
resources :author
end
When I run
rake routes
I get the following
admin_author_index GET /admin/author(.:format) admin/author#index
POST /admin/author(.:format) admin/author#create
new_admin_author GET /admin/author/new(.:format) admin/author#new
edit_admin_author GET /admin/author/:id/edit(.:format) admin/author#edit
admin_author GET /admin/author/:id(.:format) admin/author#show
PUT /admin/author/:id(.:format) admin/author#update
DELETE /admin/author/:id(.:format) admin/author#destroy
From what I can tell I am expecting the named paths to have a
_path
at the end. I am rather green at this. I have searched and searched but I could just be using the wrong terms to find the answer. Any help is appreciated. Thanks!
-edit- I should add that
<%= form_for [:admin, #author] do |f| %>
<%= f.label :first_name %>
<%= f.text_field :first_name %>
<%= f.label :last_name %>
<%= f.text_field :last_name %>
<%= f.submit %>
<% end %>
Gives me errors saying it can not find admin_author_path
You can append either _path or _url to these. Basically everything looks good.
So for example
admin_author_index GET /admin/author(.:format) admin/author#index
the helper method can be admin_author_index_path or admin_author_index_url. These helpers can be used in controllers and views to point to a controller/action or url. Read this link http://guides.rubyonrails.org/routing.html to understand more.
No. The route name does not have the _path suffix.
Refer to Rails routing from inside in for more information. It explains routing in great detail.
-Newbie to Ruby on Rails and integrating a few aspects of Twitter Bootstrap in (or at least trying :))-
I have a link in regular HTML with Twitter Bootstrap icons in it:
<li class="sidebar"><i class="icon-user"></i> Home</li>
(The i tag is for twitter's image icons)
If I were writing that same HTML in embedded Ruby, how could I still get the icon in there?
Right now I have:
<%= link_to content_tag(:li, "Home"), root_path %>
Is it possible to specify Twitter's tag in embedded ruby?
Also, should I specify the sidebar class in regular html or with :class => "sidebar"
Thanks!
Sure, just try something like:
<%= content_tag(:li, :class => 'sidebar') do %>
<%= link_to '#' do %>
<%= content_tag :i, '', :class => 'icon-user' %> Home
<% end -%>
<% end -%>
The shorter alternative I use is
link_to " ".html_safe, '#'
It's 'dirtier' but somewhat easier to understand.
This is my first time developing a rails app from scratch. The goal of my code is to use a title and link (both stored in a database table) to redirect users to the link. (Problem) When I click the link title, I'm redirected to localhost:3000/google.com instead of google.com. (Assuming google.com was the value in link.link)
<h1>Links#index</h1>
<% #links.each do |link| %>
<p>
<%= link_to link.title, link.link %>
</p>
<% end %>
Notes:
(1) Using Rails 3.1
(2) The contents of my routes.rb file are below (Not sure if the use of resources :links has something to do with my problem)
CodeHed::Application.routes.draw do
resources :links
get "links/index"
root :to => "links#index"
end
Are your links prefixed with "http://"? If not, try adding that in programmatically with something like:
def add_http(link)
if (link =~ /http(?:s)?:\/\//)
link
else
"http://#{link}"
end
end
If that doesn't work then you could simply enter raw html:
<h1>Links#index</h1>
<% #links.each do |link| %>
<p>
<%= link_to title, add_http(link) %>
</p>
<% end %>
(I haven't checked this code)
In my Rails3 app I have:
<%= link_to "Sign out", destroy_user_session_path %>
I know how to localize text, but how to localize link text? I defined "sign_out" in tried:
<%= link_to t( sign_out ), destroy_user_session_path %>
But it generates an error:
undefined local variable or method `sign_out'
What is the correct syntax?
PS: It is even more basic than this question, but I could not find any answer.
<%= link_to t('sign_out'), destroy_user_session_path %>
And you must define the key sign_out: in your local yml file after
How about link_to t("sign_out"), destroy_user_session_path?
<%= link_to t(:sign_out), destroy_user_session_path %>
or
<%= link_to t('sign_out'), destroy_user_session_path %>
You can check other details here.