Ruby on rails 将信息从视图发送到控制器rails
我累坏了。以下是我的活动表单视图:Ruby on rails 将信息从视图发送到控制器rails,ruby-on-rails,ruby,ruby-on-rails-3,ruby-on-rails-4,Ruby On Rails,Ruby,Ruby On Rails 3,Ruby On Rails 4,我累坏了。以下是我的活动表单视图: <%= form_for(@event) do |f| %> <div class="form-group"> <%= f.radio_button :repeat, 'once', checked: true%><br> <%= f.label :repeat_once, 'once'%><br> <%= f.r
<%= form_for(@event) do |f| %>
<div class="form-group">
<%= f.radio_button :repeat, 'once', checked: true%><br>
<%= f.label :repeat_once, 'once'%><br>
<%= f.radio_button :repeat, 'daily'%><br>
<%=f.label :repeat_daily, 'daily'%><br>
<%= f.radio_button :repeat, 'weekly'%><br>
<%= f.label :repeat_weekly, 'weekly'%><br>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
还有我的迁移:
def change
add_column :events, :repeat , :string
end
问题在于if块,因为无论我在视图中的选择如何(例如,我选择每周,但无论如何应用程序每天只做一次),每次都是真的。代码怎么了?感谢阅读:)等待任何想法显然,字符串总是真实的
您的属性应该是布尔的您应该在
if
语句中使用双等于=
。否则,您将为@事件指定“每日”。重复,而不检查是否已将其设置为“每日”
我认为你应该使用
if @event.repeat == 'daily'
////
end
instead of
if @event.repeat = 'daily'
////
end
@event.repeat='daily'正在分配要重复的'daily'字符串,而不检查它使用@event.repeat=='daily'如果其他条件也是如此
if @event.repeat == 'daily'
if @event.repeat == 'daily'
////
end
instead of
if @event.repeat = 'daily'
////
end