1 Replies - 9158 Views - Last Post: 01 February 2007 - 05:08 PM Rate Topic: -----

#1 theRemix  Icon User is offline

  • D.I.C Regular

Reputation: 15
  • View blog
  • Posts: 440
  • Joined: 19-October 05

radio_button_tag helper

Posted 01 February 2007 - 02:31 PM

having trouble with radio_button helper

class PostsController < ApplicationController

  def add
	 if request.post?
		@post = Post.new(:title => params[:title], :text => params[:text], :visibility => params[:visibility], :user_id => $loggedInId)
	 end
  end


class Post < ActiveRecord::Base

  PUBLIC	= "2"
  PRIVATE   = "1"
  ANONYMOUS = "3"

  # This could be made more DRY

  def public?
	self.visibility == PUBLIC
  end

  def private?
	self.visibility == PRIVATE
  end

  def anonymous?
	self.visibility == ANONYMOUS
  end

end


# add.rhtml

<% form_tag :controller => 'posts', :action => 'add' do %> 
 <% if $loggedIn != 'anonymous' and $loggedIn != nil%>
	<p class="centered">
	<% if @post %>
		<%=radio_button_tag( 'visibility', Post::PRIVATE, :checked => @post.private?) %>private |
		<%=radio_button_tag( 'visibility', Post::PUBLIC, :checked => @post.public?) %>public |
		<%=radio_button_tag( 'visibility', Post::ANONYMOUS, :checked => @post.anonymous?) %>anonymous
	<% else %>
		<%=radio_button_tag( 'visibility', Post::PRIVATE, :checked => false)%>private |
		<%=radio_button_tag( 'visibility', Post::PUBLIC, :checked => true)%>public | 
		<%=radio_button_tag( 'visibility', Post::ANONYMOUS, :checked => false)%>anonymous
	<% end %>
	</p>
 <% end %>
	<p class="centered"> 
		Title: 
		<% if @post%>
			<%= text_field_tag 'title', @post.title, :size => 50 %> 
		<% else %>
			<%= text_field_tag 'title', nil, :size => 50 %> 
		<% end %>
		
	</p> 
	<p class="centered"> 
		<% if @post%>
			<%= text_area_tag 'text', @post.text, :size => '65x5' %> 
		<% else %>
			<%= text_area_tag 'text', nil, :size => '65x5' %> 
		<% end %>
	</p> 
	<p class="centered"> 
		<%= submit_tag 'post comment' %> 
	</p> 
<% end %>



i want 'visibility' to be checked only if it was selected by the user when it's posted, instead, it always writes checked="checked" in the html... no matter what the values of visibility is

Is This A Good Question/Topic? 1

Replies To: radio_button_tag helper

#2 theRemix  Icon User is offline

  • D.I.C Regular

Reputation: 15
  • View blog
  • Posts: 440
  • Joined: 19-October 05

Re: radio_button_tag helper

Posted 01 February 2007 - 05:08 PM

oh man nevermind....

it's

<%=radio_button_tag( 'visibility', Post::PRIVATE, checked => @post.private?) %>private |


without the :
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1