开发者

want to insert a row in a table after clicking a link in my rails app

i have a rails application from the that have a list of members, so what i want is that when ever i open a member i want to have a link so that when they click on it ,it will save the c开发者_C百科urrent date and time with the membership number.


I think you are referring to modifying the updated_at field for that record in the DB. I assume you followed proper practices here and you do have an updated_at column.

You can use the button_to helper to call you update action in the users_controller. In the controller you have, do the following:

def update
  @user = User.find(params[:id])
  @user.touch

  # render/redirect as you wish
end

Touch will set the updated_at time to the current time, alternatively you can also use model.touch(:column_name) if you have a timestamp column with a different name then updated at.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜