Getting Remove_Entry_Secure Error While Using Ruby Application

Getting remove_entry_secure error while using ruby application

It turns out there was a problem with my /tmp folder permissions. The following fixed the problem:

Steps that I followed are:

user@host-$: chmod 777 -R /tmp
user@host-$: chmod o+t -R /tmp
user@host-$: ls -l tmp
drwxrwxrwt 2 user group 4096 2009-11-21 17:01 tmp

Ruby: Secure select IN and validation in controller vs model

I would do as below:

[1] pry(main)> [1,2,3,'a', nil, ''].map(&:to_int)
NoMethodError: undefined method `to_int' for "a":String
from (pry):1:in `map'

to_int would raise an exception if it is called on a non Integer object, so if you want to validate if the pks are integers without hitting the DB, this is your best choice, hence you leave the Model with its DB related activities

Want to edit/PUT/PATCH but error says No route matches [POST]

To edit a record you

  • first, should use a GET request to get the edit form
  • second, should submit that form using a PUT/PATCH request

To get to the edit form you should link to the edit path for your entry

<%= link_to 'Edit', edit_entry_path(@entry) %>

The Rails form helpers will automatically set the form to submit with the proper method, PUT OR PATCH.

Ruby on Rails: Unable to sign out of application in production

It might be related to jQuery.

Be sure to have the following lines in your application.js file (app/assets/javascripts/application.js), before any other entry:

//= require jquery 
//= require jquery_ujs

A quick fix would be to change the signout method on devise.rb initializer (config/initializers/devise.rb):

config.sign_out_via = :get

remove item from cart rails app?

In your destroy path in your carts controller you have not destroyed the object yet.

so what you have to do there is

routes.rb

delete 'remove', path: 'destroy/:id'

carts_controller.rb

def remove
cart = session['cart']
item = cart['items'].find { |item| item['product_id'] == params[:id] }
if item
cart['items'].delete item
end
redirect_to cart_path
end

views/carts/show.html.erb

<td><%= link_to 'remove', remove_cart_path(item.product_id), method: :delete %></td>

Ruby rails can't add user entry

First open rails console using this command : rails console

Then check for existent users in your database : users = User.all
If there is existent user
remove the if condition line from the index view, it's not needed and use this code instead.

<% @users.each do |user| %>
<tr>
<td><%= user.email %></td>
<td><%= user.name %></td>
<td><%= user.password_digest %></td>
<td><%= user.password %></td>
<td><%= user.password_confirmation %></td>
</tr>
<% end %>

First, you should fix the migration. Rails provide a shortcut to generate migration by using the syntax AddXXToYY followed by your attributes where YY is your table name. So for your case use the following command:

rails g migration AddLoginToUsers name:string email:string password:string

note that you don't need to add password_confirmation in your database so to test this validation add this to your User model

validates :password, confirmation: true
validates :password_confirmation, presence: true

It will add a password_confirmation as virtual attribute only for validation.
Now you can test the changes but note that the minimum password length is 6 so you have to change your user test data inside your controller or use your form as normal. Final check, copy the view block that I posted in the answer.



Related Topics



Leave a reply



Submit