Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Object in hidden_field_tag becomes nil when partial is called into an index (yet, works in individual Show view)
- <% content_for(:scripts) do %>
- <%= javascript_include_tag 'rating_ballot'%>
- <% end %>
- <div id="talesFeedHome">
- <p class="notice"><%= notice %></p>
- <%= render @tales.sort_by { |tale| tale.created_at }.reverse %>
- </div>
- <p class="clear"> </p>
- <% if signed_in? %>
- <div id="homeTales">
- <ul>
- <div id="taleShow">
- <div id="controlPanel">
- <li id="taleUserName"><%= tale.user.name %></li>
- <li id="averageRating"> Your Rating:<br /><%= render "tales/stars" %></li>
- </div>
- <div id="taleDisplay">
- <li><%= link_to(tale) do %>
- <span><%= tale.title %> </span>
- <span><%= tale.content %></span>
- <% end %>
- </li> <br />
- </div>
- </div>
- </ul>
- </div>
- <% else %>
- ...
- <div id="starRating">
- <%= form_for(rating_ballot, :remote => true, :html => { :class => 'rating_ballot' }) do |f| %>
- <%= f.label("value_1", content_tag(:span, '1'), {:class=>"rating", :id=>"1"}) %>
- <%= radio_button_tag("rating[value]", 1, current_user_rating == 1, :class => 'rating_button') %>
- <%= f.label("value_2", content_tag(:span, '2'), {:class=>"rating", :id=>"2"}) %>
- <%= radio_button_tag("rating[value]", 2, current_user_rating == 2, :class => 'rating_button') %>
- <%= f.label("value_3", content_tag(:span, '3'), {:class=>"rating", :id=>"3"}) %>
- <%= radio_button_tag("rating[value]", 3, current_user_rating == 3, :class => 'rating_button') %>
- <%= f.label("value_4", content_tag(:span, '4'), {:class=>"rating", :id=>"4"}) %>
- <%= radio_button_tag("rating[value]", 4, current_user_rating == 4, :class => 'rating_button') %>
- <%= f.label("value_5", content_tag(:span, '5'), {:class=>"rating", :id=>"5"}) %>
- <%= radio_button_tag("rating[value]", 5, current_user_rating == 5, :class => 'rating_button') %>
- <%= hidden_field_tag(:tale_id, @tale.id) %>
- <% end %>
- </div>
- Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id
- class PagesController < ApplicationController
- def home
- @tales = Tale.all
- end
- end
- class TalesController < ApplicationController
- respond_to :html, :js
- def new
- @tale = Tale.new
- end
- def show
- @tale = Tale.find(params[:id])
- end
- def index
- @tales = Tale.all
- @tale = Tale.find(params[:id])
- end
- ...
- class RatingsController < ApplicationController
- before_filter :authenticate_user!
- respond_to :html, :js
- def create
- @tale = Tale.find_by_id(params[:tale_id])
- @rating = Rating.new(params[:rating])
- @rating.tale_id = @tale.id
- @rating.user_id = current_user.id
- if @rating.save
- respond_to do |format|
- format.html { redirect_to @tale, :notice => "Your rating has been saved" }
- format.js
- end
- end
- end
- def update
- @rating = current_user.ratings.find_by_tale_id(params[:tale_id])
- @tale = @rating.tale
- if @tale and @rating.update_attributes(params[:rating])
- respond_to do |format|
- format.html { redirect_to @tale, :notice => "Your rating has been updated" }
- format.js
- end
- end
- end
- end
Add Comment
Please, Sign In to add comment