Home Ruby form helper get sucked with older value

# Ruby form helper get sucked with older value

user8241
1#
user8241 Published in September 19, 2018, 9:08 am

I got blocked while trying to get the right value after value overwriting before submitting the form from a CircleCreateService From my Circle create Service I have this:

def step_trigger(case_action)
case case_action
when 'User never create a circle'
'ncreate'
when 'User has created once'
'onecreate'
when 'User has created many'
'mcreated'
end
end


And this is what I saved into my database. So my problem is, from my form, when I am trying to edit the Circle, how can I get the old value from the db using a helper method to render corresponding option based on the retrieved data from my db?

This is my helper method:

def get_old_cirle_option(options)
case options
when 'ncreate'
'User never create a circle'
when 'oncecreate'
'User has created once'
when 'mcreated'
'User has created many'
end
end


And in my form I use this:

<%= select_tag :c_options,
options_from_collection_for_select(
get_old_cirle_option(@circe.state)),
class: "form-control" %>


the it says: undefined methodmap' for nil:NilClass Did you mean? tap

• options_from_collection_for_select expects an Enumerable as the first argument but there are clearly other issues as well. First get_old_cirle_option(@circe.state) is returning nil which means @circe.state is not one of 'ncreate','oncecreate', or 'mcreated'`. Second I have no idea what your intention was for this to begin with. – engineersmnky Apr 13 at 20:39
• First thank you for your reply. What I wanted is to be able to edit the cercle state because I will have a large filter based on the cercle state for my users. but I can't save them into the db, and in the mean time the user should be able to understand, that's why I used text, from the form and overwrite in the service before saving – Mashkour Apr 13 at 22:46
• put a default condition to check the value and the return value should be an array instead of a string. – Gagan Gupta Apr 18 at 7:58