Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/53.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 在将slim转换为erb时遇到问题_Ruby On Rails_Ruby_Ruby On Rails 4_Erb - Fatal编程技术网

Ruby on rails 在将slim转换为erb时遇到问题

Ruby on rails 在将slim转换为erb时遇到问题,ruby-on-rails,ruby,ruby-on-rails-4,erb,Ruby On Rails,Ruby,Ruby On Rails 4,Erb,我有这样的语法: = form_for(@influencer.relationships.build(followed_id: @influencer.id)) do |f| div = f.hidden_field :followed_id = f.submit "Follow", class: "btn btn-large btn-primary" 这是我找到的erb,但它不工作 <%= form_for(@influencer.relationships.build(fo

我有这样的语法:

= form_for(@influencer.relationships.build(followed_id: @influencer.id)) do |f|
  div = f.hidden_field :followed_id
  = f.submit "Follow", class: "btn btn-large btn-primary"
这是我找到的erb,但它不工作

<%= form_for(@influencer.relationships.build(followed_id: @influencer.id)) do |f| %>
    <% f.hidden_field :followed_id %>
  <%= f.submit "Follow" %>
<% end %>

因此,您将得到:

<%= button_to "Follow", @relationship %>


您的隐藏字段需要doh!谢谢你!有趣的是,将slim转换为erb的原因是什么?我想在erb中使用一些slim代码?我所有的东西都是用erb写的,我的朋友加了这个代码,他用slim写的,所以我更喜欢用erb写的。
#app/models/influencer.rb
class Influencer < ActiveRecord::Base
   has_many :relationships, foreign_key: :follower_id
end

#app/controllers/relationships_controller.rb
class RelationshipsController < ApplicationController
   def new
      @influencer = Influencer.find params[:influencer_id]
      @relationship = @influencer.relationships.build #-> "followed_id" SHOULD be a foreign key in the model. If you have it in the model, you won't need to explicitly define it
   end
end
<%= button_to "Follow", @relationship %>