2015-04-06 51 views
0

我在制作Joe's Goals的克隆。我有一个非常粗糙的版本,我用铁轨脚手架建造。本周的表格有7天和习惯的名字。我的问题是,如何从index.html.erb视图中增加出现次数(表示您习惯于这种习惯的频率),而无需输入编辑表单。 我在S.O上看了一些东西。在我的控制器中构建自定义方法 如何在我的索引表字段中创建link_to,以便它更改整数。我的Table看起来像。其设置方式是这样的:Rails 4:从索引视图中更改整数

class CreateWeeks < ActiveRecord::Migration 
    def change 
    create_table :weeks do |t| 
     t.string :habit 
     t.boolean :gob 
     t.integer :sunday 
     t.integer :monday 
     t.integer :tuesday 
     t.integer :wednesday 
     t.integer :thursday 
     t.integer :friday 
     t.integer :saturday 


     t.timestamps null: false 
    end 
    end 
end 

正如你可以看到我把一对夫妇的上/下箭头显示什么,我试图做的。现在他们只是链接到我的根路径。正如我所说,我希望他们改变所选字段中的整数值。顺便说一下,我只在周一放这个箭头。

在我的控制,我有:

def increase 
    @week = Week.find(params[:id]) 
    @week.update_attribute("monday", monday += 1) 
    @week.save 
    flash[:notice] = "Habit Increased." 
end 

我试图增加与此链接的整数

<%= link_to "+ 1", :method => :increase, :monday => @increase %> 

回答

0

您正在使用AJAX?如果你不是,那么你应该在rails上使用AJAX。您可以检查这documentation,也可能是这video将帮助你实现你所需要的。