rails combine the mail_to and button_to together - ruby-on-rails

In rails, now I have mail_to, it shows up purely as a link, when i click on it, it leads me to my email application. how can i change it to a button using twitter bootstrap?
now i have
= mail_to #my.email, "#{#my.name}",:subject=>#my.email_subject
Anyway to change the link appear as a button?
I tried out the following
= button_to #my.email, "#{#my.name}",:subject=>#my.email_subject
but it still doesnt work....

You should use = mail_to #my.email, "#{#my.name}",:subject=>#my.email_subject, :class => 'button'
Hence, you must have some CSS which defines the class button.

Related

How to create a href tag with link_to and action 'create'

I want to create a href tag like href=contacts/create. In my contacts_controller, I have a create GET action. I know this is against rails convention. I still need to create the above link using options = {controller=> 'contacts', action=>'create'}. It works for any other arbitrary action name
You can the hardcoded path option:
<%= link_to "Create", "contacts/create" %>
or the Rails generated path option:
<%= link_to "Create", { controller: "contacts", action: "create" } %>
This is not just against Rails' convention, but against sounds HTTP usage. This often causes serious problems that you can't predict in advance. Web crawling is just one of them, where something like the Google bot accidentally creates a new contact in your database, simply by crawling the page. Or script kiddies who find you have a create link, and send 100,000 clicks to it in quick succession.
Numerous other issues happen like this, including, at one well-known time, Google Chrome pre-fetching GET urls from the page to "speed up the user experience"; this was felt far and wide by sites that had used this technique. It's not an idle warning or a style issue: this can have a disastrous impact on your site.
First off this is really bad idea since GET requests should be idempotent. You're not just flouting convention - you're setting yourself and your users up for a really bad time since for example pressing the back and forward buttons will cause resources to be created - over and over. And there is guaranteed a better way to solve whatever you are trying to do such as:
# a "discrete form"
<%= button_to "Create contact", contacts_path, method: :post %>
# or use the rails ujs
<%= link_to "Create contact", contacts_path, method: :post %>
If you ABSOLUTELY have do this:
Rails.application.routes.draw do
get "contacts/create"
end
You can now do:
<%= link_to "Create", { controller: 'contacts', action: 'create' } %>
Congratulations, you broke the internets.
Like you mentioned, this is against rails convention, but if absolutely necessary, you can do this from your controller:
options = {controller=> 'contacts', action=>'create'}
view_context.link_to url_for(options)
If you need the href to only be the path, you can do:
options = {controller=> 'contacts', action=>'create'}
view_context.link_to url_for(options.merge(only_path: true))

Adding hyperlink in mail

My requirement is to add a link to mail sent from application developed in Ruby On Rails. Clicking that link in mail need to route user to that particular record in the application.
Can someone please help me with this some sample code.
In your view template use _url. E.g.:
<%= link_to 'Edit User', edit_user_url(#user) %>
it will return the complete URL.
You can use a simple link_to method in the mail or you could use a simple anchor tag. The latter you would have to build up.
If you need information on how to build links and paths check the rails guides. This has an example on the first section of the guide.
e.g. <%= link_to 'Patient Record', patient_path(#patient) %>
Besides this you need to provide more information if you want more help.
If you are starting with Ruby On Rails I would recommend looking at the videos on rails cast.
For your email problem you can look at sending-html-email
Also in the email I like to use the link_to helper like this
<%= link_to 'Click Me', something_url(#user.id), %>
I hope that this works. And Happy Coding

link_to in liquid template

I am new in Ruby on rails and facing issue while creating link_to using Liquid gem. I want to create a link in the email template like:
{{link_to 'Submit', profile_accounts_url(:account_id => account.id)}}
However, link is not created in email template. Please help me. Thanks in advance.
I didn't use liquied before, but you can check the syntax for link_to here.
using Liquid variables inside of a liquid tag call
http://richonrails.com/articles/liquid-templating-engine
However, I think you're using rails' syntax for link_to instead of liquid's syntax. Maybe you should just use something like:
<%= link_to "Submit", profile_accounts_path(account) %>
which will redirect to the show page.

how do put %span inside rails link_to in haml

font awesome inside link_to helper with haml
how should I do?
i have this code
.link_header
{link_to_ledger(current_ledger) span.icon-flag }
help please
Just pass span as block to link_to helper method something like following:
.link_header
= link_to_ledger(current_ledger) do
span.icon-flag
There are two options for link in rails
As simple
= link_to 'my link text', controllers_path
As you want to do
.link_header
= link_to_ledger(current_ledger) do
%span.icon-flag
-# you can also do what ever you want here even table/images can also be added

Can I use :method => :delete with url_for()?

I'm using Devise for authentication and creating an item in a dropdown for Sign Out. This is how I've built it:
<span data-icon="" /> Sign Out
I'm using an icon font to stick a nice little image in to the left of the text. With Devise, it uses the DELETE verb for the destroy_user_session_path route. Most people would use a button_to or link_to but I don't think this will work for me. Using link_to is going to stick in the closing tag automatically, which won't allow me to put my span tag in. Is there a way for me to build the above link and use the DELETE verb?
For now I'm using the solution in this thread. Specifically changing config.sign_out_via = :delete to config.sign_out_via = :get in devise.rb.
Just add data-method="delete" to your link tag. This is what link_to does when you call it with :method => :delete. JQuery does the rest of the work.
<span data-icon="" /> Sign Out

Resources