Quick one! -- Project Messages!

Hi Guys,

The answer to this is probably pretty simple but I have an app which
holds projects, and have messages for each project.

project has_many messages
message belongs to project

in my project controller i just do

@project_messages = @project.messages.collect

In my project view page you can see the messages (but they are truncated
to save space). I want to have a “more” link that takes the user to
another page which holds all the full project messages.

Do I create a page called messages.html.erb?

I would also like to be able to comment on each of the messages on the
second page!?!?

Please can someone help me as I am a really stuck!

Thank you very much!!

Dave

In my project view page you can see the messages (but they are truncated
to save space). I want to have a “more” link that takes the user to
another page which holds all the full project messages.

Do I create a page called messages.html.erb?

I would also like to be able to comment on each of the messages on the
second page!?!?

Please can someone help me as I am a really stuck!

Thank you very much!!

Dave

Anyone?

What did you name the method in your project controller?

On Jan 5, 5:40 am, Dave S. [email protected]

Do you want the second page to contain all the messages or just 1
message?

Cheers, Sazima

On Jan 5, 8:40 am, Dave S. [email protected]

Sazima wrote:

Do you want the second page to contain all the messages or just 1
message?

Cheers, Sazima

On Jan 5, 8:40�am, Dave S. [email protected]

all the messages for a particular project, and then a section under for
comments to be made for each message (kind of indented if you know what
i mean)

Dave S. wrote:

Sazima wrote:

Do you want the second page to contain all the messages or just 1
message?

Cheers, Sazima

On Jan 5, 8:40�am, Dave S. [email protected]

all the messages for a particular project, and then a section under for
comments to be made for each message (kind of indented if you know what
i mean)

i just thought i could create a partial and reference to it from both
the project view page and another page such by passing in the project id
somehow.

Bobnation wrote:

What did you name the method in your project controller?

On Jan 5, 5:40�am, Dave S. [email protected]

Hi,

Im not sure if I am going about this the right way but, ive created a
partial called _message in the project view with the following link;


<% for message in @project_messages %>
<%= render :partial => “message”, :object => message %>
<% end %>

and the following code in the _message partial.


<%= message.status %> - <%= message.title %>
<%= truncate(message.body, 60, "...") %> <%= link_to 'continue...', message_path(@project) %>

This works to view the messages within the project view page.

But I want to be able to view all the messages for a project in thier
entirety on a different page and create comments for each message…

My Projects controller show def currently looks like this;

def show
@project = Project.find(params[:id])
@project_tasks = @project.tasks.collect
@project_messages = @project.messages.collect

respond_to do |format|
  format.html # show.html.erb
  format.xml  { render :xml => @project }
end

end

Sazima wrote:

Do you want the second page to contain all the messages or just 1
message?

Cheers, Sazima

On Jan 5, 8:40�am, Dave S. [email protected]

?

If this 2nd page you want will contain only 1 message, then it is the
standard show action + view… Otherwise you can add a named route and
use whatever name you want for the action and view. But it can be
trickier to add comments.

Cheers, Sazima

On Jan 5, 3:05 pm, Dave S. [email protected]

  1. Route (config/routes.rb):

map.with_options(:controller => ‘messages’) do |m|
m.messages ‘/messages’, :action => ‘messages’
end

  1. Action (app/controllers/messages_controller.rb):

def messages
# Retrieve messages the same way you did in the index action
end

  1. View (app/views/messages/messages.html.erb) => do the same as in
    index, but showing the whole message…

Cheers, Sazima

On Jan 5, 3:20 pm, Dave S. [email protected]

Sazima wrote:

If this 2nd page you want will contain only 1 message, then it is the
standard show action + view… Otherwise you can add a named route and
use whatever name you want for the action and view. But it can be
trickier to add comments.

Cheers, Sazima

On Jan 5, 3:05�pm, Dave S. [email protected]

ok if for now i say i just want all messages, no comments. how would i
go about adding the named route and view?

Sazima wrote:

  1. Route (config/routes.rb):

map.with_options(:controller => ‘messages’) do |m|
m.messages ‘/messages’, :action => ‘messages’
end

  1. Action (app/controllers/messages_controller.rb):

def messages
# Retrieve messages the same way you did in the index action
end

  1. View (app/views/messages/messages.html.erb) => do the same as in
    index, but showing the whole message…

Cheers, Sazima

On Jan 5, 3:20�pm, Dave S. [email protected]

im slightly confused. i was returning the messages in the projects
controller by doing

@project_messages = @project.messages.collect

Ryan,

If I understood correctly, he already has an index action that shows
truncated messages. He asked for a 2nd page to show the whole content
of all messages.

He would probably be better off using a nested route for only 1 action
(index) and retrieving the rest of the message asynchronously with
AJAX on-demand, but that might be too much at once.

Cheers, Sazima

Woah.

Firstly, why are you calling .collect on project.messages and
everything? This is unnecessary.

Secondly, if messages is an association for a project it would be
better if you used nested routes, as explained here:
rails.info
. Your controller would be called messages_controller and the action
would be called index, not messages.

Ryan B.
Freelancer

Ryan B. wrote:

Woah.

Firstly, why are you calling .collect on project.messages and
everything? This is unnecessary.

Secondly, if messages is an association for a project it would be
better if you used nested routes, as explained here:
rails.info
. Your controller would be called messages_controller and the action
would be called index, not messages.

Ryan B.
Freelancer
http://frozenplague.net

Thanks for your help.

Ive created a nested route, and now have my messages for the project
which is fine. The next problem comes from getting the comments for each
message in this index page.

I am not quite sure how I can retrieve the comments per message in the
index in my controller…


Ryan B.
Freelancer
http://frozenplague.net

Thanks for your help.

Ive created a nested route, and now have my messages for the project
which is fine. The next problem comes from getting the comments for each
message in this index page.

I am not quite sure how I can retrieve the comments per message in the
index in my controller…

any ideas at all?

Dave S. wrote:


Ryan B.
Freelancer
http://frozenplague.net

Thanks for your help.

Ive created a nested route, and now have my messages for the project
which is fine. The next problem comes from getting the comments for each
message in this index page.

I am not quite sure how I can retrieve the comments per message in the
index in my controller…

any ideas at all?

i am having the same problem as this for another part of the system.

i need to collect on the projects index page a list of the invoices
associated with that project but am unsure how to do this. It is easy on
the view page as you can loop through and collect them, but how can I do
this on the index page?

The answer to this will answer the previous questions as well…!