Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 72531

rails haml file, looping through values and linking to them

$
0
0

I have two models, downtowns and properties. The relationship is one to many, one downtown, many properties. What I have been having trouble doing is display and link to a list of each downtown's properties on the downtown's show page.

What i wind up getting instead of an actual link to each property, i'm getting html text instead displayed in what would almost appear to be a string, but no executable path.

Instead of just getting downtown property 1 as a link, i wind up getting this below. <a href="/downtowns/1/properties/1">downtown property 1</a>

My route file is:

resources :downtowns do
    resources :properties
  end

my downtown controller is

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

my properties controller

  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

and finally my downtown show page

%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. 

If anyone would have any ideas i'd be grateful!


Viewing all articles
Browse latest Browse all 72531

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>