How to get a string from Proc.new

Added by Tide _ about 4 years ago

I am trying to create a plugin. In my init.rb I am reading a setting.
I am doing it like this : @new_window = Proc.new { Setting.plugin_test['new_window'] }
When I try to say if @new_window == "0" I am not getting a string.
I actually end up with an object that is still a proc.

How do I convert this to a string so I can see if it is 0 or 1?
I can see the setting in my database so I know I am just down to converting this proc to a string.

Thanks

Replies (28)

RE: How to get a string from Proc.new - Added by Yuki Kita about 4 years ago

I have set up a github account for the plugin.

Congratulations!
Keep on working.

I had some trouble trying to add the require user to be logged in option. There is not a method for setting the condition like we did the html_options.

I think that the menu option ":if" would solve the problem like this.
(I'm not confident that it would work properly.)

  menu(:top_menu,
      :link,
      Proc.new { Setting.plugin_menu_link['link_item_text'] },
      :caption => Proc.new { Setting.plugin_menu_link['link_item_name'] }
      :if =>  Proc.new {(Setting.plugin_menu_link['requires_user_logged_in'] == '1') && User.current.logged?})

RE: How to get a string from Proc.new - Added by Tide _ about 4 years ago

Hey Yuki,

Yes this is the normal way

  menu(:top_menu,
      :link,
      Proc.new { Setting.plugin_menu_link['link_item_text'] },
      :caption => Proc.new { Setting.plugin_menu_link['link_item_name'] }
      :if =>  Proc.new { User.current.logged? })

Your way basically says only show it if we say yes to "Require logged" and if the current user is logged in. It works fine but this is not what we are after. I need to find a way to say if we require the user to be logged in then add this

:if =>  Proc.new { User.current.logged? }

if we do not require the user to be logged in then remove that or set it to nil somehow.

RE: How to get a string from Proc.new - Added by Tide _ about 4 years ago

For anyone interested the answer to the last post was to use

:if =>  Proc.new {(Setting.plugin_menu_link['requires_user_logged_in'] == '1') & User.current.logged?})

We have finished up making the first version of the plugin.

You can read about it here : http://www.redmine.org/boards/3/topics/12779
You can download it here : http://github.com/Tide/menu_link

1 2 (26-28/28)