How to structure Rails link so that clicking it will update an ActiveRecord attribute -
I have two models, a property model and an app model. There are many properties in the application, and the property is an application_id in the property model, such as the application_id, which indicates the application associated with the property.
I want to show a list of all the potential applications on the property show page, a link to the application which, if clicked, will update the application_id just in the property model in the ID of that application.
Here is my relevant code:
view / properties /show.html.erb this is not working though Can anyone help me how can I link to link_to the code so that I can do that which I am trying to do? Interesting questions! You want to do something like this: This will allow you to call: - If you use the above link, you will be able to use an administrator as:
select an application template : & Lt; Ol class = "microposts" & gt; & Lt;% @ owner.application.each do | Template | & Gt%; & Lt; Li & gt; & Lt;% = link_to "Application # {template.id}" ,: admin = & gt; "Attribute",: verb = & gt; "Update" ,: Method = & gt; : Put, application_id = & gt; Template.id% & gt; & Lt; / Li & gt; & Lt;% end% & gt; & Lt; / Ol & gt; Edit @ Owner = User.find (property.find (params [: id]). User_id) end def update @ property = property.find (params [: id]) if @ property.update_attributes (property_params) flash [: success] = Added # application @ redirect_to @property to replace redirects; It's just for this job and now redirect_to @property end-end personal DF property param.require (property). (Addresses ,: zipcode,: application_template_id) End
# config / routes.rb Processing: Patch properties (" # - & gt; Domain.com/properties/2/update_app/4 End
< Code> # app / view / properties / show.html .erb & lt;% = link_to "update", property_update_app_path (application_id), method :: patch% & gt;
#Apps / Controller / Property-Controller RB class multiplier control & lt; ApplicationController def update_app @property = Property.Fand Paramat [: id] @ property.update ({application_id: params [: app_id]}) End End
Comments
Post a Comment