I would like to know, is it possible to handle the params object at update action to create a new model instead of edit the current model?
What I am trying to do, is to store the edit attempt into a new model for review purpose, then when approved I will implement the update of model using the same params object that were sent in the first place of edit.
But, how would I save the param object to use later when admin approve the edit?
Am I at the right track to approve edit before eventually implement the update?
I'd use a gem like https://github.com/airblade/paper_trail to solve this issue.
Have a look at this screencast:
http://railscasts.com/episodes/255-undo-with-paper-trail
Related
I have a custom module for user to upload some information and files
I can use forms and make the module accessible from the website but I need them to be able to edit there recored also, exactly like if they are internal user but only for y custom module
anyone knows how to do that thank u very much in advance.
edit
after reading the comment of #KevalMehta
I think my question should be how to update a record from a form
this is my code to create a new record in my module
request.env['manager.create_company_link'].sudo().create(kw)
so first I think I need the id of the record I need to update before how to update it
I thing #KevalMehta is referring to me using .sudo() how to give the right access
I can see that getRecord call has CREATEORREAD action. Is it possible to make it read only? I need it to properly limit client permissions.
Thank you in advance!
Do you mean to avoid creating it if user does not have permissions? If the user does not have permissions for UPDATE or PATCH this will stop him from being able to update anything, but we don't yet have an individual READ action to avoid the record from being created initially. We'll raise that as an issue and try implement it soon.
Edit:
Issue created on github
I'm trying to keep track of the number of comments made about a user in my application. These comments can be made by other user and of course these other users can't update the User they're commenting about. So i was wondering if there was any way to do this with Cloud code on Parse.
Edit :I'm also looking to update a value called "latestPostTime" that will get the current time of the latest post. any help would be amazing thank you
You can, have a look at beforeSave and afterSave triggers. For example you can create an afterSave trigger for your comments class and then update the user object the comment has been made on/about.
Have a look at the Cloud Code documentation for the triggers, that should help to get you started.
If you run into ACL issues, you can enable usage of the master key in a Cloud Code function as well to update the count field of the user object.
Quite new to rails/spree and am trying to create a pdf uploader where users can upload images that will then be sent to the company but when I try to send it I get an undefined local variable or method for 'spree_current_user'.
This is the line that gives the error. I know this would normally grab the id (I have used the same line in controllers) but I am not sure why it wouldn't work within the order mailer.
pdfs = Pdf.where(user_id: spree_current_user.id, created_at: Date.today-1.hour)
Basically I'm just wondering if anybody knows what else I could do? I tried to pass it through the controller as a session[] but this didn't work either.
If there are any other files that you might need to look at then please let me know. Would very much appreciate any help !
Thanks in advance.
You can't access the session or Controller helpers (which spree_current_user is one of). You must pass controller-level information to the objects (mailers) you want them in.
So the calling code for the uploader object must pass in the user id into the object where you want it. Since you didn't specify what object that is (exactly) I can't really answer out of context. But as a general rule session-level concepts (like the current user) belong to the controller, and if you want them elsewhere (outside of the controller) you need to pass them along with the call to the objects that are called from the controller.
If that's not possible, a first-order association (like adding user_id to the object in question) is also a good solution, depending on your domain model.
I have solved this issue if anyone else is needing it. What I did was pass the user id through a hidden field in the view:
hidden_field_tag 'current_user', spree_current_user.id
Then I added it in the controller
OrderMailer.send_to_client(..., ..., ..., params[:current_user]).deliver
I then changed my original pdf line to account for pdfs created in between certain times:
pdfs = Pdf.where(user_id: current_user, pdf_updated_at: Time.now-1.hour..Time.now)
As well as sending it through in this method.
def send_to_client( ..., ..., ..., current_user)
Hope this helps if anyone is experiencing a similar issue :).
I do not find any way in order to modify the behaviour of the existing methods in rails_admin. I am using rails 3.2 and integrated with PostgreSql.
I want to modify the behaviour of one of my method during the edit. I have a model of shipment_quotes and model has a charges column, by default this field is blank and I want if admin add any amount in this field then after submitting the form a mail will be shoot to particular user.
But I have not found any way to modify the admin methods.
Also I want to create new actions for particular model.
Please help me I really fed up with this. After so much googling I do not find any thing relevant.
Any help will be really appreciated...
Rails Admin wouldn't do this for you. You might as well create a callback method for shipment_quotes after create. I think something like this would help
class ShipmentModel < ActiveRecord::Base
after_create :verify_charges
private
def verify_charges
if !charges.blank?
# Then shoot an email
end
end
end
Rails admin would then just handle your CRUD.