Rails Formtastic – How to remove the unordered list from form inputs

When using ‘Formtastic’ the default behavior is to add an unordered list to the set of inputs. ¬†This is specified in its CSS. ¬† This makes the form look like it has a set of radio bullets.

How to remove this?

From an input:

<%=f.input :zip, :label => false, :placeholder => '5 digit zip',
           :input_html => { :class => 'form-control' },
           :wrapper_html => { :style => 'list-style-type:none;' } %>

From a button:

 <%= f.action :submit, :label => "Continue", 
              :button_html => { :class => 'btn btn-danger' },
              :wrapper_html => { :style => 'list-style-type:none;' }%>

 

Advertisements

How to create a guest user in Rails 4

If you have Devise authentication:

 

class ApplicationController < ActionController::Base

  protect_from_forgery

  # if user is logged in, return current_user, else return guest_user
  def current_or_guest_user
    if current_user
      if session[:guest_user_id] && session[:guest_user_id] != current_user.id
        logging_in
        guest_user(with_retry = false).try(:destroy)
        session[:guest_user_id] = nil
      end
      current_user
    else
      guest_user
    end
  end

  # find guest_user object associated with the current session,
  # creating one as needed
  def guest_user(with_retry = true)
    # Cache the value the first time it's gotten.
    @cached_guest_user ||= User.find(session[:guest_user_id] ||= create_guest_user.id)

  rescue ActiveRecord::RecordNotFound # if session[:guest_user_id] invalid
     session[:guest_user_id] = nil
     guest_user if with_retry
  end

  private

  # called (once) when the user logs in, insert any code your application needs
  # to hand off from guest_user to current_user.
  def logging_in
    # For example:
    # guest_comments = guest_user.comments.all
    # guest_comments.each do |comment|
      # comment.user_id = current_user.id
      # comment.save!
    # end
  end

  def create_guest_user
    u = User.create(:name => "guest", :email => "guest_#{Time.now.to_i}#{rand(100)}@example.com")
    u.save!(:validate => false)
    session[:guest_user_id] = u.id
    u
  end

end