Call Controller Actions in View

Issues related to building and deploying Ruby on Rails.
no avatar
shreekumar
 
Posts: 1
Joined: Sun Aug 21, 2011 3:30 pm
Location: Mysore

Call Controller Actions in View

by shreekumar » Sun Aug 21, 2011 3:37 pm

Hi guys, basically i'm .Net Developer, now learning RoR :)

I've a problem as follows..

1] I Created a Controller called pages_controller.rb
Code: Select all
class PagesController < ApplicationController
  def index
    primary
    render('primary')
  end
  def primary
    @pages = Page.find(:all, :conditions => ["IsParent = ? or Name = ?",true, "Home"], :order => 'id')
  end
def secondary
    @pages = Page.find(:all, :conditions => ['ParentID = ?', params[:id]], :order => 'id')
    @parentpage=Page.find(params[:id])
   
    if @pages.count<=0
      @parentpage.IsParent=false
      redirect_to(:action => 'primary')
    else
      @parentpage.IsParent=true
    end
    @parentpage.save
  end
end


and in View, I'm listing all the page like this

Code: Select all
<% pages ||= [] %>
<ul>
<% pages.each do |page| %>
   <% if page.Name=="Home" %>
      <li><%= link_to_unless_current(page.Name, :action => 'index') %></li>
    <% else %>
      <li><%= link_to_unless_current(page.Name, :action => 'show', :id => page.UrlWord) %></li> 
    <% end %>
  <% end %>
</ul>


Finally, my question is how to call a Action secondary in this view?

Return to Ruby on Rails