Ruby on rails 如何在选择表单后调用模型上的方法

Ruby on rails 如何在选择表单后调用模型上的方法,ruby-on-rails,Ruby On Rails,在选择菜单上进行选择后,我正在尝试更新模型 例如,如果选择是“se”,我想调用一个更新当前用户配置文件的方法 我的观点是: <h1>Profiles#new</h1> <p>Find me in app/views/profiles/new.html.erb</p> <%= simple_form_for @profile do |f| %> <%= f.input :bio %> <%= select_tag i

在选择菜单上进行选择后,我正在尝试更新模型

例如,如果选择是“se”,我想调用一个更新当前用户配置文件的方法

我的观点是:

<h1>Profiles#new</h1>
<p>Find me in app/views/profiles/new.html.erb</p>

<%= simple_form_for @profile do |f| %>
<%= f.input :bio %>

<%= select_tag id="postcode"name="Areas Covered">
    <option value="se">Southeast London</option>
    <option value="nw">  </option>
    <option value="n">  </option>
    <option value="s">  </option>
  </select>
 <br><br>

<%= f.button :submit %>
<% end %>
Profiles#新增
在app/views/profiles/new.html.erb中查找我

伦敦东南部

如果调用“se”,我将调用“se_london”助手方法:

module ProfilesHelper

    def se_london
        se = Place.where('area2 LIKE ? AND postal_code LIKE ?', '%London%', '%se%')
        @profile.places << se
    end
end
moduleprofileshelper
伦敦大学
se=Place.where('area2 LIKE?和邮政编码LIKE?'、'%London%'、'%se%'))

@profile.places最好阅读一下如何使用
选择标签
。你可以这样做:

<%= label_tag :areas_covered, "Areas Covered" %>
<%= select_tag :areas_covered, options_for_select(['se', 'nw', 'n', 's']) %>
现在,在您的控制器中,您正在测试字符串“value”是否等于变量,或者是否等于名为
se
的方法的返回值,就我所见,该方法甚至没有定义。这个测试永远不会通过,甚至会抛出一个错误

<%= label_tag :areas_covered, "Areas Covered" %>
<%= select_tag :areas_covered, options_for_select(['se', 'nw', 'n', 's']) %>
@profile.se_london if params[:areas_covered] == 'se'