Send Email Again in device system in rails - devise

I have a question about the area to send again the email to confirm the account.
The previous developer of the website added this
<%- if devise_mapping.confirmable? && controller_name != 'confirmations' %>
<%= link_to 'Send Email Again', new_confirmation_path(resource_name) %>
<% end -%>
Why?
I am new on rails, but I don't undestand why he added this if condition.
Also because I noted that I can see this link both logged both not logged.

Related

configure an existing controller to display devise notifications: undefined local variable or method `resource'

I have created a Rails 3 app with devise and i also have a controller called 'account' . When an user signs in with devise's sign in view , he's redirected to a view of account controller. So the notifications od devise "sign in successful" etc are not displayed. When i tried adding
<%= devise_error_messages! %>
to this view It gave an error
NameError in Account#welcome
undefined local variable or method `resource' for #<#:0x4e9fe70>
Can anyone pls tell me how to make this account controller display devise's notifications??
I tried reading the docs in github but didnt help..
I guess we have do modify routes file as its showing error in resources..
Update1:
Layout file:
<div id="maincontent">
<div class="entry">
<% flash.each do |name, msg| %>
<%= content_tag :section, msg, :id => "flash_#{name}", :class => "flash" %>
<% end %>
<!--<p class="commentbar"> Signup</p>-->
<%= yield %>
</div>
</div>
Once you installed Devise, there will be a block of guide. One paragraph is about the messages:
Ensure you have flash messages in app/views/layouts/application.html.erb.
For example:
<p class="notice"><%= notice %></p>
<p class="alert"><%= alert %></p>
So, to display success messages/notice, use
<%= notice %>
<%= alert %>
These two are also Rails default helper to show flash messages. So you are fine with both Devise and other normal flash messages with this setting.

Redirecting outside a web app?

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)

Rails 3 show text field unless it has just "#"

In my Rails 3 web app, I have a Twitter text field in one of the forms and on the user page it displays it.
<%= f.label :twitter, "Twitter Username" %>
<%= f.text_field :twitter, :value => "#" %>
And on the user page:
<% if #user.twitter? %>
<div class="twitter"><%= #user.twitter %></div>
<% end %>
The problem is, when a user doesn't enter their Twitter username into the field, it keeps # in the field and displays it on the user page. Because of this I would like to make it so if it just has # then it doesn't display it.
Looks like the # value gets persisted into the database if the user doesn't specify a twitter name, right? Are you sure you want that?
You could, in the controller, when saving the user, do something like:
user.twitter = params[:user][:twitter] unless params[:user][:twitter] == "#"
This will ensure that the User#twitter field only gets set if something is specified.
But to answer your question specifically, you can do something like this in the view:
<%= #user.twitter == "#" ? "(not provided)" : #user.twitter %>

Email send to friend functionality?

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

Forgotten Password in Rails

I am trying to implement a forgotten password solution in rails. I have a form for the user to enter the email address for their registered account, and I intend to have a mailer email them a unique URL that will link them to a password reset page.
My config/routes.rb file has the following routes:
resources :users do
collection do
get :lost_password #the account-email submisison form url
get :reset_password #a url for the function that sends the response email
end
end
When I run rake routes from the console, I get the paths I want:
lost_password_users GET /users/lost_password(.:format) {:action=>"lost_password", :controller=>"users"}
reset_password_users GET /users/reset_password(.:format) {:action=>"reset_password", :controller=>"users"}
users GET /users(.:format) {:action=>"index", :controller=>"users"}
POST /users(.:format) {:action=>"create", :controller=>"users"}
BUT! When the user hits the submit button on the form outlined in the code below:
<h3>Reset Password</h3>
<%= form_for(:user, :url => reset_password_users_path) do |f| %>
<p>Enter the email address you used to register for this site.</p></br>
<div class="field">
<%= f.label :email %> </br>
<%= f.text_field :email %>
</div>
<div class="actions">
<%= f.submit "Send Email" %>
</div>
<% end %>
I get a
No route matches
"/users/reset_password"
error through the ActionController.
I do, in fact, have views and controller functions defined for both the lost_password_users_path and the reset_password_users_path, so I'm puzzled as to why I would run into this routing error.
I have two questions:
Why would the ActionController raise this error, when I clearly have the path, methods, and views defined?
Has anyone else implemented a password reset in RoR, and can you lend any insight as to whether or not this approach is good practice?
Thanks in advance!
Try changing get :reset_password to post :reset_password in routes.rb
function of reset password: I hope,it will be work, use in controller update function
if params[:user][:password].present?
puts "present"
puts params[:current_password]
if (params[:user][:password] == "")
params[:user].delete(:password)
else
if #user.valid_password?(params[:current_password])
#updated = true
puts #updated.to_s
#user.update_attributes(user_params)
sign_in(#user,:bypass => true)
flash[:notice] = "Password Updated Successfully"
redirect_back fallback_location: user_url
else
#updated = false
puts #updated.to_s
flash[:danger] = "Current Password does not matched"
redirect_back fallback_location: user_url
end
end