0

我对 Rails 比较陌生,最近设法断开了指向我的一个模型内容的链接......

之前在 stackoverflow 上发布了一个问题,我调整了to_param模型中的函数,以便将产品名称附加到产品 ID。

我所做的更改是:

products.rb,

def to_param
  "#{id}-#{product_name.parameterize}"  
end

routes.rb,

match '/:id' => 'uniquewetsuits#show'

这成功地创建了我希望的地址/products/ID-product-name,但是,我收到一条错误消息,指出没有带有 的产品ID=ID-product-name

如果我导航到/products/ID,我可以正常成功地查看该页面。

任何人都可以告诉我如何重新连接事物,以便我得到更长的 ID 字符串的匹配项吗?

谢谢你的时间

编辑

控制器的内容是:

 def index

#@search = Uniquewetsuit.search(params[:q])
#@findwetsuits = @search.result(:distinct => true)

#if @findwetsuits.count > 0
 # @uniquewetsuits = @findwetsuits.all
#else
  @uniquewetsuits = Uniquewetsuit.all
#end

respond_to do |format|
  format.html # index.html.erb
  format.xml  { render :xml => @uniquewetsuits }
end
end

# GET /uniquewetsuits/1
# GET /uniquewetsuits/1.xml
def show
@uniquewetsuit = Uniquewetsuit.find(params[:id])

respond_to do |format|
  format.html # show.html.erb
  format.xml  { render :xml => @uniquewetsuit }
end
end

# GET /uniquewetsuits/new
# GET /uniquewetsuits/new.xml
def new
@uniquewetsuit = Uniquewetsuit.new

respond_to do |format|
  format.html # new.html.erb
  format.xml  { render :xml => @uniquewetsuit }
end
end

# GET /uniquewetsuits/1/edit
def edit
@uniquewetsuit = Uniquewetsuit.find(params[:id])
end

# POST /uniquewetsuits
# POST /uniquewetsuits.xml
def create
@uniquewetsuit = Uniquewetsuit.new(params[:uniquewetsuit])

respond_to do |format|
  if @uniquewetsuit.save
    format.html { redirect_to(@uniquewetsuit, :notice => 'Uniquewetsuit was successfully created.') }
    format.xml  { render :xml => @uniquewetsuit, :status => :created, :location => @uniquewetsuit }
  else
    format.html { render :action => "new" }
    format.xml  { render :xml => @uniquewetsuit.errors, :status => :unprocessable_entity }
  end
end
end

# PUT /uniquewetsuits/1
# PUT /uniquewetsuits/1.xml
def update
@uniquewetsuit = Uniquewetsuit.find(params[:id])

respond_to do |format|
  if @uniquewetsuit.update_attributes(params[:uniquewetsuit])
    format.html { redirect_to(@uniquewetsuit, :notice => 'Uniquewetsuit was successfully updated.') }
    format.xml  { head :ok }
  else
    format.html { render :action => "edit" }
    format.xml  { render :xml => @uniquewetsuit.errors, :status => :unprocessable_entity }
  end
end
end

# DELETE /uniquewetsuits/1
# DELETE /uniquewetsuits/1.xml
def destroy
@uniquewetsuit = Uniquewetsuit.find(params[:id])
@uniquewetsuit.destroy

respond_to do |format|
  format.html { redirect_to(uniquewetsuits_url) }
  format.xml  { head :ok }
end
end
4

0 回答 0