2015-04-06 27 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將幫助你實現你所需要的。