Not able to update the password in Rails 5 web app - ruby-on-rails-4

In My Rails 5 Web App. I have installed Devise gem in it. When I wan to edit my password by clicking on link below but instead on going to the page for update password. Page get refreshed and It gives alert message you are already logged in .
I am using Below link in my Application:
<%= link_to('Edit Password' , edit_user_password_path)%>
Routes Files is as:
devise_for :users, controllers: { sessions: "users/sessions" }
Please suggest me the changes to redirect to edit password page all other links like below are working.
<%= link_to('Edit Registration',edit_user_registration_path )%>
<%= link_to "Sign out", destroy_user_session_path, :method => :delete %>
<%= link_to('Edit Registration', edit_user_registration_path) %>
<%= link_to('Edit Password', edit_user_password_path) %>

Related

Must provide source or customer

getting an error with stripe in local testing transfer recipients.
I check SQL lite browser and the user has a stripe recipient ID
I tried clearing my entire database, creating a new listing and then placing an order and getting the same error. not sure of the cause of this error, and help would be great!
Stripe::InvalidRequestError in OrdersController#create
Must provide source or customer.
begin
charge = Stripe::Charge.create(
:amount => (#listing.price * 100).floor,
:currency => "usd",
:card => token
This was a turbo-links issue. I fixed the issue by inputting the following code
<% if user_signed_in? %>
<%= link_to 'New Listing', new_listing_path, class: "btn btn-link", data: { no_turbolink: true } %>
<% end %>

Rails 4 Manage File based Translations at Admin End

I am working on a rails website and I need to make it multilingual. I have created yml files for the languages needed for translation.
What I want is to provide the Admin access to files to edit them instead of browsing through the files, by a section in Admin panel. Is there any gem for managing translations through Admin end.
I have never implemented translations before.
By default Rails uses YAML files to store internationalization information. But we are not restricted to use YAML (that is only capable of reading translations but cannot dynamically store them). We can use any database as backend.
To start, you can use this gem: https://github.com/svenfuchs/i18n-active_record
You can change the default backend like that:
I18n.backend = Globalize::Backend::Static.new
You can also use Chan backend to chain multiple backends together.
# config/initializers/locale.rb
I18n.backend = I18n::Backend::Chain.new(I18n::Backend::ActiveRecord.new, I18n.backend)
But, As the translations are accessed frequently in every request page, ActiveRecord is not the best approach. For these reason, a key-value store is the way to go.
You can use Redis database for this:
First install Redis
$ brew install redis
Install redis gem:
# Gemfile
source 'http://rubygems.org'
# ...
gem 'redis'
Now you can change the backend like that:
# config/initializers/locale.rb
I18n.backend = I18n::Backend::KeyValue.new(Redis.new)
Code to add translation:
# /app/views/admin/translations/index.html.erb
<%= form_tag admin_translations_path do %>
<p>
<%= label_tag :locale %><br>
<%= text_field_tag :locale %>
</p>
<p>
<%= label_tag :key %><br>
<%= text_field_tag :key %>
</p>
<p>
<%= label_tag :value %><br>
<%= text_field_tag :value %>
</p>
<p><%= submit_tag "Submit" %></p>
<% end %>
This form will POST to admin/TranslationsController's create action:
# /app/controllers/admin/translations_controller.rb
module Admin
class TranslationsController < ApplicationController
# ....
def create
I18n.backend.store_translations(params[:locale]), {params[:key] => params[:value]}, escape: false)
redirect_to admin_translations_path, notice: "Translation Added"
end
end
end
You can also use redis-i18n gem to do the same: https://github.com/redis-store/redis-i18n

Rails 4 - link_to with confirm in Rails

I'm trying to customize my dialog confirm the link_to in rails 4. But I do not understand why he rides the html as "confirm", and should be "data-confirm"!
I've tried a number of ways, and it is always generated "confirm", like this:
<%= link_to 'Delete', user, :method => :delete, :confirm => 'Are you sure?' %>
<a confirm="Are you sure?" rel="nofollow" data-method="delete" href="/user/13">Delete</a>
I followed this tutorial:
http://thelazylog.com/custom-dialog-for-data-confirm-in-rails/
and i used the example in tutorial, but also doesn't work
Confirm has been deprecated in rails 4.
So use new syntax:
<%= link_to "title", "#", data: {confirm: "Are you sure!"} %>
To get the same behavior in rails 7 you should use turbo_confirm key instead:
<%= link_to 'Delete', user,
data: {turbo_method: :delete, turbo_confirm: 'Are you sure?'} %>

RubyonRails Guide confusion over link creation in Ruby

I am a beginner to Rails. Was working along with Railsguide for Rails 4.
One confusion i have is:
for adding a link , somewhere it is written like:
<h1>Hello, Rails!</h1>
<%= link_to "My Blog", controller: "posts" %>
whereas somewhere its like
<%= link_to 'New post', new_post_path %>
Please clarify the difference.
Good question. Both of these are link helpers, and both are resource-oriented (check out the Rails UrlHelper docs for more information).
The first one will render a link that is associated with the particular controller:
<%= link_to "My Blog", controller: "posts" %>
<a href='/posts'>
The second will render the Rails path specific to creating a new Post object (this is also resource-oriented). Check out section 2.3 in the Rails routing guide:
<%= link_to 'New post', new_post_path %>
<a href='/posts/new'>

error getting path returned rails 4

I'm trying to access my page gallery/new via a link, so i have created this
<%= link_to 'New gallery' new_gallery_path %>
rake routes gives
gallery_index_path GET /gallery(.:format) gallery#index
POST /gallery(.:format) gallery#create
new_gallery_path GET /gallery/new(.:format) gallery#new
edit_gallery_path GET /gallery/:id/edit(.:format) gallery#edit
gallery_path GET /gallery/:id(.:format) gallery#show
PATCH /gallery/:id(.:format) gallery#update
PUT /gallery/:id(.:format) gallery#update
DELETE /gallery/:id(.:format) gallery#destroy
and within my routes i have
resources :gallery
My view at gallery/new is
<%= nested_form_for #gallery, :html => { :multipart => true} do |f| %>
--content here
<% end %>
whenever i click the link to view this page i get
undefined method `galleries_path
Can someone point out my mistake, please?
You've chosen the wrong name for your resources. It should always be pluralized:
resources :galleries
From this Rails will generate the plural and singular paths correctly. galleries_path for the index, gallery_path for show, etc etc.