0

if else 有问题——我认为这是一个语法问题,但我似乎无法理解。我使用了下面的建议,它仍然抛出 500 错误。我不知道确切的错误,因为有一条自定义错误消息,并且“a 500”是唯一给出的技术信息。是否有我可以在开发端启用的调试模式来提供更多信息?

我想要做的是显示一个下拉菜单,如果您是“DSD”则允许选择,否则下拉菜单应该被禁用,这就是我需要 IF 语句的原因。

这是我正在运行的当前 if 语句:

更新

        <% 
           if (sign_on.acctypw1.strip =="DS") 
               select_tag(:distributor_number_X,  options_for_select(distributors_array), {:style => "width:400px", :disabled => "true"}) 
           else (sign_on.acctypw1.strip =="DSD")               
               select_tag(:distributor_number_X, options_for_select(distributors_array), {:style => "width:400px" })
           end
        %>

这是来自服务器日志的错误:

[Mon Mar 25 09:33:41 2013] [notice] caught SIGTERM, shutting down
[ pid=8710 thr=77929640 file=utils.rb:176 time=2013-03-25 09:33:42.922 ]: *** Exception SignalException in PhusionPassenger::ClassicRails::ApplicationSpawner (SIGTERM) (process 8710, thread #<Thread:0x94a3950>):
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/passenger-3.0.1/lib/phusion_passenger/abstract_server.rb:343:in `select'
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/passenger-3.0.1/lib/phusion_passenger/abstract_server.rb:343:in `server_main_loop'
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/passenger-3.0.1/lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously'
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/passenger-3.0.1/lib/phusion_passenger/abstract_server.rb:180:in `start'
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/passenger-3.0.1/lib/phusion_passenger/classic_rails/application_spawner.rb:149:in `start'
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/passenger-3.0.1/lib/phusion_passenger/spawn_manager.rb:219:in `block (2 levels) in spawn_rails_application'
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/passenger-3.0.1/lib/phusion_passenger/abstract_server_collection.rb:132:in `lookup_or_add'
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/passenger-3.0.1/lib/phusion_passenger/spawn_manager.rb:214:in `block in spawn_rails_application'
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/passenger-3.0.1/lib/phusion_passenger/abstract_server_collection.rb:82:in `block in synchronize'
from <internal:prelude>:10:in `synchronize'
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/passenger-3.0.1/lib/phusion_passenger/abstract_server_collection.rb:79:in `synchronize'
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/passenger-3.0.1/lib/phusion_passenger/spawn_manager.rb:213:in `spawn_rails_application'
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/passenger-3.0.1/lib/phusion_passenger/spawn_manager.rb:132:in `spawn_application'
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/passenger-3.0.1/lib/phusion_passenger/spawn_manager.rb:275:in `handle_spawn_application'
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/passenger-3.0.1/lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop'
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/passenger-3.0.1/lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously'
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/passenger-3.0.1/helper-scripts/passenger-spawn-server:99:in `<main>'
[Mon Mar 25 09:35:50 2013] [notice] Apache/2.2.14 (Ubuntu) Phusion_Passenger/3.0.1 configured -- resuming normal operations
 [Mon Mar 25 10:03:31 2013] [notice] caught SIGTERM, shutting down
 [Mon Mar 25 10:03:47 2013] [notice] Apache/2.2.14 (Ubuntu) Phusion_Passenger/3.0.1 configured -- resuming normal operations
4

3 回答 3

4

我假设这是在您的视图中(erb.html 文件)您的 if 和 else 语句也必须放在里面<% %>

<% if sign_on.acctypw1.strip =="DS" %>
  <%= select_tag(:distributor_number_X, options_for_select(distributors_array), {:style => "width:400px", :disabled => "true"}) %>
<% else sign_on.acctypw1.strip =="DSD" %>             
  <%= select_tag(:distributor_number_X, options_for_select(distributors_array), {:style => "width:400px" })  %>
<% end %>

还有一点要记住——

<% "This will be evaluated" %>
<%= "This will be evaluated and outputted to your view" %>
于 2013-03-22T15:55:37.180 回答
0

你想使用elsif而不是 else 那里。

您还需要包装您if/elsif/end<% %>标签,因为这是 ERB

于 2013-03-22T15:55:08.383 回答
-1
<%= 
   if (sign_on.acctypw1.strip =="DS") 
       select_tag(:distributor_number_X,  options_for_select(distributors_array), {:style => "width:400px", :disabled => "true"}) 
   else (sign_on.acctypw1.strip =="DSD")               
       select_tag(:distributor_number_X, options_for_select(distributors_array), {:style => "width:400px" })
   end
%>
于 2013-03-22T16:03:12.070 回答