lundi 23 mars 2015

Ruby Rails - How can I assign a new value to an attribute via link_to?

I have a model called projects, and it has an attribute, :opstatus, which I would like to set to 3 (opstatus is an int). I need this to happen when the user clicks the following link:



<%= link_to 'Close', projects_path, :action => :newmeth %>


For which I created the method (in the projects_controller):



def newmeth
@project.update_attribute(:opstatus, 3)
end


But when the user clicks the link, nothing happens! The database tells me that opstatus still =s 3, and there is no error message.


Can anyone give me a clue as to what I have done wrong? Thanks!


Below is the entire contents of my routes.rb file


Rails.application.routes.draw do



get 'sheetread/show'
get 'sheetread' => 'sheetread#show'

get 'users/index'

get 'users/new'
get 'welcome/index'
get 'signup' => 'users#new'

get 'login' => 'sessions#new'
post 'login' => 'sessions#create'
delete 'logout' => 'sessions#destroy'

resources :users
resources :spreadsheets


resources :projects do
resources :comments
end

priority.

root 'welcome#index'

Aucun commentaire:

Enregistrer un commentaire