Newbie doubt in links and controllers

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,

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.

  redirect\_to\(@entry, :notice =&gt; &#39;Elaborator setted successfully&#39;\)
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: <p> <b><%= t('entries.fields.geomatics_elaboration') %>:</b> <% if @entry.geomatics_elaboration_id.nil? and current_user.geomatics %> <%= link_to entry, :confirm => 'Are you sure?', :method => :set_elaborator do %> <img src="../images/buttons/Delete.png" title="Elaborate this entry"/> <% 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 %> </p> <p> <b><%= t('entries.fields.geomatics_review') %>:</b> <% if @entry.geomatics_checker_id.nil? and current_user.geomatics %> <%= link_to @entry, :confirm => 'Are you sure?', :method => :set_reviewer do %> <img src="../images/buttons/Delete.png" title="Review this entry"/> <% 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 %> </p> 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 :confused: )

Regards,

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