Forum: Ruby on Rails Quick one! -- Project Messages!!

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
428f1d76da99d9602d57b046841df29a?d=identicon&s=25 Dave Smith (railsnoob)
on 2009-01-05 11:40
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
428f1d76da99d9602d57b046841df29a?d=identicon&s=25 Dave Smith (railsnoob)
on 2009-01-05 12:40
> 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?
247cd3d37084a3d6794076207bd9fbd7?d=identicon&s=25 Bobnation (Guest)
on 2009-01-05 16:21
(Received via mailing list)
What did you name the method in your project controller?

On Jan 5, 5:40 am, Dave Smith <rails-mailing-l...@andreas-s.net>
428f1d76da99d9602d57b046841df29a?d=identicon&s=25 Dave Smith (railsnoob)
on 2009-01-05 16:29
Bobnation wrote:
> What did you name the method in your project controller?
>
> On Jan 5, 5:40�am, Dave Smith <rails-mailing-l...@andreas-s.net>

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.

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

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
Fac81a9d95c81d817a2debb6f717f3ac?d=identicon&s=25 Sazima (Guest)
on 2009-01-05 16:31
(Received via mailing list)
Do you want the second page to contain all the messages or just 1
message?

Cheers, Sazima

On Jan 5, 8:40 am, Dave Smith <rails-mailing-l...@andreas-s.net>
428f1d76da99d9602d57b046841df29a?d=identicon&s=25 Dave Smith (railsnoob)
on 2009-01-05 16:33
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 Smith <rails-mailing-l...@andreas-s.net>

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)
428f1d76da99d9602d57b046841df29a?d=identicon&s=25 Dave Smith (railsnoob)
on 2009-01-05 17:22
Dave Smith 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 Smith <rails-mailing-l...@andreas-s.net>
>
> 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.
428f1d76da99d9602d57b046841df29a?d=identicon&s=25 Dave Smith (railsnoob)
on 2009-01-05 18:05
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 Smith <rails-mailing-l...@andreas-s.net>

?
Fac81a9d95c81d817a2debb6f717f3ac?d=identicon&s=25 Sazima (Guest)
on 2009-01-05 18:16
(Received via mailing list)
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 Smith <rails-mailing-l...@andreas-s.net>
428f1d76da99d9602d57b046841df29a?d=identicon&s=25 Dave Smith (railsnoob)
on 2009-01-05 18:20
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 Smith <rails-mailing-l...@andreas-s.net>

ok if for now i say i just want all messages, no comments. how would i
go about adding the named route and view?
Fac81a9d95c81d817a2debb6f717f3ac?d=identicon&s=25 Sazima (Guest)
on 2009-01-05 19:12
(Received via mailing list)
1. Route (config/routes.rb):

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

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

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

3. 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 Smith <rails-mailing-l...@andreas-s.net>
428f1d76da99d9602d57b046841df29a?d=identicon&s=25 Dave Smith (railsnoob)
on 2009-01-05 20:32
Sazima wrote:
> 1. Route (config/routes.rb):
>
>   map.with_options(:controller => 'messages') do |m|
>     m.messages '/messages', :action => 'messages'
>   end
>
> 2. Action (app/controllers/messages_controller.rb):
>
>   def messages
>      # Retrieve messages the same way you did in the index action
>   end
>
> 3. 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 Smith <rails-mailing-l...@andreas-s.net>

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

@project_messages = @project.messages.collect
9a2a53db8e9b4476038c94a64b32833f?d=identicon&s=25 Ryan Bigg (ryan-bigg)
on 2009-01-05 22:05
(Received via mailing list)
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:
http://guides.rails.info/routing_outside_in.html
. Your controller would be called messages_controller and the action
would be called index, not messages.
-----
Ryan Bigg
Freelancer
http://frozenplague.net
Fac81a9d95c81d817a2debb6f717f3ac?d=identicon&s=25 Sazima (Guest)
on 2009-01-06 15:12
(Received via mailing list)
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
428f1d76da99d9602d57b046841df29a?d=identicon&s=25 Dave Smith (railsnoob)
on 2009-01-06 16:16
Ryan Bigg 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:
> http://guides.rails.info/routing_outside_in.html
> . Your controller would be called messages_controller and the action
> would be called index, not messages.
> -----
> Ryan Bigg
> 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....
428f1d76da99d9602d57b046841df29a?d=identicon&s=25 Dave Smith (railsnoob)
on 2009-01-07 11:00
>> -----
>> Ryan Bigg
>> 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?
428f1d76da99d9602d57b046841df29a?d=identicon&s=25 Dave Smith (railsnoob)
on 2009-01-07 14:52
Dave Smith wrote:
>
>>> -----
>>> Ryan Bigg
>>> 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..!
This topic is locked and can not be replied to.