Hi there,
well, I''m trying to follow an idea I''ve seen somewhere else
but can''t
get it customized to my needs.
Situation: I have a plant model, a user model and a garden model.
Plant model has_many :gardens
User model has_many :gardens
Garden model belongs_to :user and belongs_to :plant
I''ve choosen garden being a rich joined table because I want additional
information in it, like notice, etc.
Everybody might be able to see the list of plants by the index view and
detailed information in the show view. I wanted the system to be gently,
so if the user is not logged in he gets an information "become a member,
add the plant to your garden, etc." As the user logs in, he might go as
well through the index and follow that up to the show action but then
I''m checking if the plant already exists in the garden or not. This is
releasing different actions.
plants_controller:
def show
@plant = Plant.find_by_id_and_published(params[:id], true)
@title = @plant.name_deu
if is_logged_in?
@plant_in_garden = Garden.find_by_user_id(params[:id].to_i)
else
@plant_in_garden = nil
end
show of plant:
<h1>
<%= h(@plant.name_deu) %>
<% if is_logged_in? && @plant_in_garden || nil %>
<span class="violet_color">is already in your
garden.</span>
<% end %>
</h1>
<% if is_logged_in? && @plant_in_garden == nil %>
<p>
I don''t know which code to write here ;)
</p>
<% end %>
This all works well right now. I put some data in the gardens table.
Logged in and logged out, with and without plant in garden great.
Now, how to get the plant into the garden with one click??? Now we get
back to the idea I''ve seen.
routes.rb:
map.resources :plants,
:member => { :enable => :put, :disable => :delete },
:collection => {:admin => :get}
One guy did it with the posibility as an admin for enabling and
disabling members:
<% unless user == logged_in_user -%>
<% if user.enabled -%>
<%= link_to image_tag("key_delete.png"), user_url(user.id),
:method
=> :delete %>
<% else -%>
<%= link_to image_tag("key_add.png"), enable_user_url(user.id),
:method => :put %>
<% end -%>
<% end -%>
and in the controller:
def destroy
@user = User.find(params[:id])
if @user.update_attribute(:enabled, false)
flash[:notice] = "User has been disabled."
else
flash[:error] = "User couldn''t be disabled."
end
redirect_to :action => ''admin''
end
def enable
@user = User.find(params[:id])
if @user.update_attribute(:enabled, true)
flash[:notice] = "User has been enabled."
else
flash[:error] = "User couldn''t be enabled."
end
redirect_to :action => ''admin''
end
So, how to get that running for my needs? The above code isn''t using a
joined table. It is writing in the user model itself an setting the
enabled flag. I need it in an joined table.
Am I wrong, am I right? How to get where I want to be? Any help?
Greetings,
Mayo
--
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
-~----------~----~----~----~------~----~------~--~---