Hi all, I’ve the following doubt.
I’ve this controller methods:
def set_elaborator
@entry = Entry.find(params[:id])
@entry.geomatics_elaboration_id = current_user.id
if @entry.save!
redirect_to(@entry, :notice => ‘Elaborator setted successfully’)
end
end
def set_reviewer
@entry = Entry.find(params[:id])
@entry.geomatics_checker_id = current_user.id
if @entry.save!
redirect_to(@entry, :notice => ‘Elaborator setted successfully’)
end
end
So, I want to add a link in the show view, like this:
<%= t('entries.fields.geomatics_elaboration') %>:
<% if @entry.geomatics_elaboration_id.nil? and
current_user.geomatics %>
<%= link_to entry, :confirm => 'Are you sure?', :method =>
:set_elaborator do %>
<% end %>
<% elsif @entry.geomatics_elaboration_id.nil? and not
current_user.geomatics %>
<%= t('entries.messages.not_assigned_yet') %>
<% else %>
<%= User.find(@entry.geomatics_elaboration_id).fullname %>
<% end %>
<%= t('entries.fields.geomatics_review') %>:
<% if @entry.geomatics_checker_id.nil? and current_user.geomatics %>
<%= link_to @entry, :confirm => 'Are you sure?', :method =>
:set_reviewer do %>
<% end %>
<% elsif @entry.geomatics_checker_id.nil? and not
current_user.geomatics
%>
<%= t('entries.messages.not_assigned_yet') %>
<% else %>
<%= User.find(@entry.geomatics_checker_id).fullname %>
<% end %>
I want to, when I click the link update the @entry and load the show
template with the changes…
Any suggestion?
Regards,
TSU. Amador Cuenca
On 7 February 2011 17:32, Amador Antonio C. [email protected]
wrote:
Hi all, I’ve the following doubt.
I’ve this controller methods:
def set_elaborator
@entry = Entry.find(params[:id])
@entry.geomatics_elaboration_id = current_user.id
if @entry.save!
This should be save, not save!. save! generates an exception if it
fails rather than returning false.
So, I want to add a link in the show view, like this:
<%= t(‘entries.messages.not_assigned_yet’) %>
<% end %>
<% elsif @entry.geomatics_checker_id.nil? and not current_user.geomatics
%>
<%= t(‘entries.messages.not_assigned_yet’) %>
<% else %>
<%= User.find(@entry.geomatics_checker_id).fullname %>
<% end %>
I want to, when I click the link update the @entry and load the show
template with the changes...
Any suggestion?
You have shown much too much detail and made the question too
complicated. Extract the fundamental question and demonstrate the
problem with a few lines of code if necessary.
Colin
Ok Let’s try:
I want to update a especific field from a show view when I click the
“Set
reviewer” link (assigning the current user ID), reload the same view and
see
the changes.
Fields:
*Entry.geomatics_checker_id
*User.id.
I hope you can upderstand now. (Sorry for my bad english )
Regards,
–
TSU. Amador Cuenca
On 7 Feb 2011, at 17:32, Amador Antonio C. [email protected]
wrote:
Hi all, I’ve the following doubt.
<% if @entry.geomatics_checker_id.nil? and current_user.geomatics %>
<%= link_to @entry, :confirm => 'Are you sure?', :method => :set_reviewer
do %>
Method (in this context) refers to an http method, i.e. get,post,put and
so on
Normally to do what you’re trying you’d add a route for that action to
config/routes.rb, and then you can call some_action_entry_path(entry) to
get the path to link to
Fred