2

enter image description here我在上传图片后显示图片预览。我的视图包含名称,电子邮件ID,文件上传和图片预览的人员列表。并且在提交按钮上它会将所有图片保存到各自的图片上。我坚持如何保存哈希通过回形针将每个图像分配给相应的一个。 我成功地将每个人的ID作为关键字进行散列。 我有两个控制器人和图像,这个预览和保存功能工作在新的和创建的图像。如何使用回形针将图像保存到相应的ID?

代码图像控制器:

def new 
@people = Person.where("avatar_file_name is ?",nil) 
end 

def create 
@people = Person.where("avatar_file_name is ?",nil) 

[email protected] 
u=Array.new 

@people.each do |e| 

    u.push(e.id) 
end 

    h=Hash.new 
    h=params 

    u.each do |x| 

    @newimage=h["#{x}"] 
     ######## Here in @newimage we get hash of image 
end` 
end 
end 

我有一种让每个图像的哈希后写? 任何人都需要一些更多的描述,他们可以要求.......... 预先感谢

回答

2

得到解决......很容易的

u.each do |x| 

     @person = Person.find(x) 
     @person.update_attribute(:avatar,h["#{x}"]) 

    end 

它的正常工作

相关问题