jquery - Javascript: Using a method from model in javascript code -
I am trying to set up users on an asset, and I am not in the problem of ensuring that How to max_users
method in asset.rb
in my JS code
The hardware will always be set with a maximum of 1gius, I'm trying to use the max_users method with the "coded gem" so that the "end more" button disappears. While the software never has a max_user value.
Should work as Max_users, as is profile_type. JS works, but instead always stops at 1, I have to register it in the max_user, and show / hide based on it.
Any help would be greatly appreciated. And thank you in advance.
JS:
$ -> Check_to_hide_add_link = - & gt; If $ ("# assets_users. Nested-fields") is a length of 1 $ ("# assets_users."). Hide () and $ ("# assets_users .a link"). Show () $ ("# assets_users") .bind "cocoon: post-enter", - & gt; Check_to_heide_ad_link () $ ("# assets_users"). Tie "Cocoon: Later-Delete", - & gt; Check_to_hide_add_link () check_to_hide_add_link ()
assets. Show:
- If @ asset.users.empty? = Simple_form_for ([@ asset_profile, @asset]) do | F | | = F.input: max_users, such as: Hidden #sets_users = f.simple_fields_for: assets_users do | Assets_user | = "Assets_user_fields", f: assets_user .link = link_to_add_association "Add another user", f ,: assets_users = f.submit
_assets_user_fields:
. Nested-fields = f.input: user_id, archive: @ users.order (: last_name) ,: label = gt; "User" = link_to_remove_association "remove", f
assets. Rb:
def max_users if self.asset_profile.profile_type == "hardware" ends 1 end. . . Def length_of_users if user_ids.count & gt; Max_users errors.add (: user, "You can only add maximum # {max_users} users") End End
max_users
was to be retrieved, and it had to be converted to an integer, after which it has been plugged only if the field volume is high, or If the maximum is equal to, the form will stop generating new fields.
$ -> Check_to_hide_add_link = - & gt; Val_users = parseInt ($ ("# asset_max_users"). Val (), 10) If $ ("# assets_users. Nested-fields"). Length & gt; = Max_users $ ("# assets_users .a link"). Hide () and $ ("# assets_users .a link"). Show () $ ("# assets_users"). Tie "Cocoon: Post-Insert", - & gt; Check_to_heide_ad_link () $ ("# assets_users"). Tie "Cocoon: Later-Delete", - & gt; Check_to_hide_add_link () check_to_hide_add_link ()
Comments
Post a Comment