Last active
December 28, 2015 23:08
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ---------------------- | |
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