www.tutorialspoint.com Forum Index
Register FAQMemberlistUsergroupsTutorials PointLog in
Reply to topic Page 1 of 1
Call Controller Actions in View
Author Message
Reply with quote
Post Call Controller Actions in View 
Hi guys, basically i'm .Net Developer, now learning RoR Smile

I've a problem as follows..

1] I Created a Controller called pages_controller.rb
Code:
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:
<% 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?

View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:
Reply to topic Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum