Hi all, I’ve been developing a Rails app, I almost finish so, I decided refactor my code. Here some doubts
1.- I’ve Job and User controllers, a user has jobs but when you create the job there isn’t user assigned.
So I’ve the myworks in the entries controller:
def myworks @entries = Entry.find_all_by_user_id(current_user.id) respond_to do |format|
format.html format.xml { render :xml => @entries } end
end
and I’ve this route:
match ‘/myworks’ => ‘entries#myworks’, :as => ‘myworks’
So I access it via the URL: localhost:3000/myworks
But I move it to the User controller (I think it’s better):
def myworks @entries = Entry.find_all_by_user_id(self.id)
respond_to do |format| format.html format.xml { render :xml => @entries } end
end
and I want to access It with this url: localhost:3000/user/1/myentries
Question: How do I to do that?
2.- I’ve this img tag many times in my views:
<img src=“<%= entry.officeentrystate ? “…/images/buttons/flag_green.gif” : “…/images/buttons/flag_red.gif”%>” title=“<%= t(‘entries.fields.officeentrystate’) %>” alt=“<%= t(‘entries.fields.officeentrystate’) %>”/>
Question: There’s a way to create a helper to do that? Like,
helper_name(title, value)
I’ll really appreciate your help.
Regards,