I want to create link_to that updates a value status (accept - 1 ,refuse - 2 cause 0 is in progress) so i had an idea to call methods in job_app
def accept
@job_apps = job_apps.find(params[:id])
@job_apps.update_attribute(:status,1)
end
def refuse
@job_apps = job_apps.find(params[:id])
@job_apps.update_attribute(:status,2)
end
routes:
get 'accept' => 'job_apps#accept'
post 'accept' => 'job_apps#accept'
It claims error that job_apps are undefined (treid job_app also). Tried:
def accept
@job_apps = @user.job_app
@job_apps.update_attribute(:status,1)
end
I had similar trouble for calling the job_app in the same view (to see job_app.status as it is table joined with users on user_id) but on stack overflow someone helped me with this (view file):
<th><%= user.job_app.status %></th>
I completely dont have idea how use it to link_to (if it is possible ofc)
it seems that you are using an enum on the status column. You can't use raw values (the integer part of the enum value) with enums unless you skip object instantiation (using update_all, or update_columns, for example).If you instantiate the object, you must use the enum value (value is :accept, while raw value is 1). In accept, you need to update the object as such
def accept
@job_apps = job_apps.find(params[:id])
@job_apps.update_attribute(status: :accept)
end
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.