Skip to content

Instantly share code, notes, and snippets.

@aamax
Last active December 28, 2015 23:08
Show Gist options
  • Save aamax/7576366 to your computer and use it in GitHub Desktop.
Save aamax/7576366 to your computer and use it in GitHub Desktop.
trying to add a field to an activerecord model to set some values at run time.
# ----------------------
class MyObj < ActiveRecord::Base
attr_accessor :i_can_select
end
# ----------------------
class MyController < ApplicationController
def index
@list = MyObj.all
# loop through all records and set the non persisted field to a value
# the value is set based on the list item properties and the current user
@list.each do |l|
l.i_can_select = complex_routine_to_set_selectability(current_user)
end
end
end
----------------------
index.html.erb.....
<% @list.each do |i| %>
<% if i.i_can_select %>
show a cool button here for a feature when it's true!
<% end %>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment