4
I have a problem I’ve never had in Java but I’m almost going crazy in Rails.
I’m developing a project where there are users and groups. So I created a separate model for relationship N:N
between users and groups.
In the group show page I created the group description, below appears the partial form _groupsuser
to allow the group creator to add users to that group. Below all this I rendered the partial to display the list of users belonging to the group.
The project has a slightly different structure because I am using partials to avoid replicating the same logic in the control and view so I would like to avoid messing around with the structure and focus only on updating the listing once I have the answer 'ajax:complete'
. In case I created in the control the create method:
def create
if group.user == current_user
@groupsuser = Groupsuser.new(groupsuser_params)
@groupsuser.group = group
if @groupsuser.save
flash[:notice] = 'User was successfully add.'
else
flash[:alert] = 'User cannot be add.'
end
else
flash[:notice] = "You didn't have permition."
end
head :ok
end
I would like to update using only ajax similar to java update method with type facelets:
<p:commandButton value="All" id="btnAll" process="@all" update="grid"
actionListener="#{personBean.savePerson}"/>
For example:
$('create_button').onClick('ajax:complete', render(@group));
to refresh the full page or
$('create_button').onClick('ajax:complete', "Comando mágico para atualizar apenas a div");
What problem did you find? If it doesn’t work, how exactly doesn’t it work? What happens to you?
– Guilherme Bernal
So, I’m not very feral in Avascript but tried everything that is way and the user is added in the table groupsuser perfectly. However, it does not update the page automatically. When I have update manually appear the :notice comments and the user in the listing, but I would like to implement a way where as soon as I click add the page already updates to show the notification and the user in the listing. I already tried to use render and redirect_to (despite losing notification) but does not update the page automatically.
– brunowff
I don’t know if this idea of mine works because I’ve been taking a look at the English OS and I found people arranging adverse solutions for me does not work because the groupsuser route is within the groups in Routes.rb. Does not have a way to update the page along with the information coming from the @gropsuser backend?
– brunowff