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

New Topic/Question
Reply


MultiQuote




|