Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/78.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
Html 如何使用Rails和Haml循环遍历值并链接到它们_Html_Ruby On Rails_Ruby_Haml - Fatal编程技术网

Html 如何使用Rails和Haml循环遍历值并链接到它们

Html 如何使用Rails和Haml循环遍历值并链接到它们,html,ruby-on-rails,ruby,haml,Html,Ruby On Rails,Ruby,Haml,我有两种型号,市中心和物业。这种关系是一对多,一对一,一对多。我在市中心的展示页面上显示和链接到每个市中心的房产列表时遇到问题 我得到的不是指向每个属性的实际链接,而是HTML文本,几乎看起来像字符串,但没有可执行路径 我得到的不是市中心物业1的链接,而是: <a href="/downtowns/1/properties/1">downtown property 1</a> 我的市区管理员是: def show @properties = Property.w

我有两种型号,市中心和物业。这种关系是一对多,一对一,一对多。我在市中心的展示页面上显示和链接到每个市中心的房产列表时遇到问题

我得到的不是指向每个属性的实际链接,而是HTML文本,几乎看起来像字符串,但没有可执行路径

我得到的不是
市中心物业1
的链接,而是:

<a href="/downtowns/1/properties/1">downtown property 1</a>
我的市区管理员是:

def show
    @properties = Property.where(downtown: @downtown_id)
  end

  def new
    @downtown = Downtown.new
  end

  def create
    @downtown = Downtown.create(downtown_params)
    if @downtown.save
      redirect_to @downtown
    else
      render 'new'
    end
  end

  def downtown_params
    params.require(:downtown).permit(:name, :city)
  end
  def new
    @property = Property.new
  end

  def create
    @downtown = property.find(id)
    @property = Property.create(params[:property_params])
    @property.downtown_id = @downtown.id

    if @property.save
      redirect_to @property
    else
      render 'new'
    end
  end

  def show
  end
我的属性控制器是:

def show
    @properties = Property.where(downtown: @downtown_id)
  end

  def new
    @downtown = Downtown.new
  end

  def create
    @downtown = Downtown.create(downtown_params)
    if @downtown.save
      redirect_to @downtown
    else
      render 'new'
    end
  end

  def downtown_params
    params.require(:downtown).permit(:name, :city)
  end
  def new
    @property = Property.new
  end

  def create
    @downtown = property.find(id)
    @property = Property.create(params[:property_params])
    @property.downtown_id = @downtown.id

    if @property.save
      redirect_to @property
    else
      render 'new'
    end
  end

  def show
  end
最后是我的市中心展示页面:

%h2= @downtown.name

- if @downtown.properties.present?
  %p 
    = @downtown.properties.map {|property| link_to(property.name, downtown_property_path(property)) }.join("<br/>")
- else
  No downtowns for now. 
%h2=@downtown.name
-如果@downtown.properties.present?
%p
=@downtown.properties.map{| property | link_to(property.name,downtown_property_path(property))}.join(“
”) -否则 现在没有市中心。
在Haml中这样做是可能的,也不太困难。我唯一做错的事情就是如何格式化它

我变了

    = @downtown.properties.map {|property| link_to(property.name, downtown_property_path(property)) }.join("<br/>")