How to show blog post in alphabetical order. Thank you. PS: New to rails and web. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On May 21, 4:19 pm, raj <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> How to show blog post in alphabetical order. > > Thank you. > > PS: New to rails and web. > > -- > Posted viahttp://www.ruby-forum.com/.You would sort them in the controller. Your controller may look like: class PostsController < ApplicationController def index @posts = Post.find(:all) ... end ... end Change the find to be: @posts = Post.find(:all, :order => "last_name, first_name") So, @posts, when it gets to the view, is ordered the way you want it. The view simply does the viewing. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I have a small problem here.... like when they click on A i am calling showa function in controller, where I get all the post whose title starts with A. This I am doing for all the alphabets. But I am trying to use only one view and redirecting to list...but it says @posts is undefined in the view. On solution is to have one view page for each alphabet but i need to have 24 pages which is a wrong design. How do I handle this. Thank you. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
raj wrote:> I have a small problem here.... > > like when they click on A i am calling showa function in controller, > where I get all the post whose title starts with A. This I am doing for > all the alphabets. But I am trying to use only one view and redirecting > to list...but it says @posts is undefined in the view. > > On solution is to have one view page for each alphabet but i need to > have 24 pages which is a wrong design. How do I handle this. > > Thank you. >Don''t call showa. call show and pass the letter as a param. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Can you be more precise, i am new bee...
this my show method
def showa
@posts=Post.find(:all, :conditions => "title LIKE
''a%''", :order=>
"id DESC")
render :action => ''list''
end
This is my view stmt
<%= link_to ''A'', :action => ''showa''
%>
Thank You.
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
def show
@posts = Post.find( :all, :conditions => [ "title LIKE
''?%''", params[
:starts_with ] ] )
render :action => ''list'';
end
--
view:
<% for alpha in (''A''..''Z'') -%>
<%= link_to alpha, { :action=> ''show'', :starts_with
=> alpha }
<% end -%>
raj wrote:> Can you be more precise, i am new bee...
>
> this my show method
> def showa
> @posts=Post.find(:all, :conditions => "title LIKE
''a%''", :order=>
> "id DESC")
> render :action => ''list''
> end
>
> This is my view stmt
>
> <%= link_to ''A'', :action =>
''showa'' %>
>
> Thank You.
>
>
My new list is
def list
@posts = Post.find( :all, :conditions => [ "title LIKE
''?%''", params[
:starts_with ] ] )
end
I am getting Mysql error :(
Mysql::Error: #42000You have an error in your SQL syntax; check the
manual that corresponds to your MySQL server version for the right
syntax to use near ''T''%'')'' at line 1: SELECT
* FROM posts WHERE (title
LIKE ''''T''%'')
RAILS_ROOT: ./script/../config/..
Application Trace | Framework Trace | Full Trace
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/active_record/connection_adapters/abstract_adapter.rb:128:in
`log''
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/active_record/connection_adapters/mysql_adapter.rb:243:in
`execute''
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/active_record/connection_adapters/mysql_adapter.rb:399:in
`select''
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/active_record/connection_adapters/abstract/database_statements.rb:7:in
`select_all''
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/active_record/base.rb:427:in
`find_by_sql''
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/active_record/base.rb:997:in
`find_every''
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/active_record/base.rb:418:in
`find''
#{RAILS_ROOT}/app/controllers/blog_controller.rb
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
right... change to: title LIKE ? and append the % on the end of the params[ :starts_with ] Ravindraraj Mamadgi wrote:> My new list is > > def list > @posts = Post.find( :all, :conditions => [ "title LIKE ''?%''", params[ > :starts_with ] ] ) > > end > > I am getting Mysql error :( > > Mysql::Error: #42000You have an error in your SQL syntax; check the > manual that corresponds to your MySQL server version for the right > syntax to use near ''T''%'')'' at line 1: SELECT * FROM posts WHERE (title > LIKE ''''T''%'') > > RAILS_ROOT: ./script/../config/.. > Application Trace | Framework Trace | Full Trace > > c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/active_record/connection_adapters/abstract_adapter.rb:128:in > `log'' > c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/active_record/connection_adapters/mysql_adapter.rb:243:in > `execute'' > c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/active_record/connection_adapters/mysql_adapter.rb:399:in > `select'' > c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/active_record/connection_adapters/abstract/database_statements.rb:7:in > `select_all'' > c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/active_record/base.rb:427:in > `find_by_sql'' > c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/active_record/base.rb:997:in > `find_every'' > c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/active_record/base.rb:418:in > `find'' > #{RAILS_ROOT}/app/controllers/blog_controller.rb > >
Thank you that worked. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---