Use rvmrc or ruby-version file to set a project gemset with RVM?

If your .rvmrc file contains custom shell code, continue using .rvmrc as it allows you to include any shell code. If your only aim is to switch Ruby versions, then use .ruby-version which is supported by other Ruby version switchers such as rbenv or chruby. This file also does not require trusting as it is … Read more

Add a CSS class to

<%= f.submit ‘name of button here’, :class => ‘submit_class_name_here’ %> This should do. If you’re getting an error, chances are that you’re not supplying the name. Alternatively, you can style the button without a class: form#form_id_here input[type=submit] Try that, as well.

How can I find out the current route in Rails?

If you are trying to special case something in a view, you can use current_page? as in: <% if current_page?(:controller => ‘users’, :action => ‘index’) %> …or an action and id… <% if current_page?(:controller => ‘users’, :action => ‘show’, :id => 1) %> …or a named route… <% if current_page?(users_path) %> …and <% if current_page?(user_path(1)) … Read more

Rails params explained?

The params come from the user’s browser when they request the page. For an HTTP GET request, which is the most common, the params are encoded in the URL. For example, if a user’s browser requested http://www.example.com/?foo=1&boo=octopus then params[:foo] would be “1” and params[:boo] would be “octopus”. In HTTP/HTML, the params are really just a … Read more

Override devise registrations controller

In your form are you passing in any other attributes, via mass assignment that don’t belong to your user model, or any of the nested models? If so, I believe the ActiveRecord::UnknownAttributeError is triggered in this instance. Otherwise, I think you can just create your own controller, by generating something like this: # app/controllers/registrations_controller.rb class … Read more

ActiveModel::ForbiddenAttributesError when creating new user

I guess you are using Rails 4. If so, the needed parameters must be marked as required. You might want to do it like this: class UsersController < ApplicationController def create @user = User.new(user_params) # … end private def user_params params.require(:user).permit(:username, :email, :password, :salt, :encrypted_password) end end

Learning Ruby on Rails

I’ve been moving from C# in my professional career to looking at Ruby and RoR in my personal life, and I’ve found linux to be slightly more appealing personally for development. Particularly now that I’ve started using git, the implementation is cleaner on linux. Currently I’m dual booting and getting closer to running Ubuntu full … Read more