Skip to content

Instantly share code, notes, and snippets.

View almaron's full-sized avatar

Ilya Levin almaron

View GitHub Profile
def show
@forum = Forum::Forum.find_by_id(params[:id])
if @forum.hidden && !(user_in?([:admins, :masters]) || user_permitted?(:show_hidden))
url = case @forum.parent_id
when 0 then forum_index_path
else forum_path(@forum.parent)
end
redirect_to url
end
rendering the forum
url = "http://napodiume.ru/profile/"+model[:id]
puts "Соединяемся с профилем №#{model[:id]}"
doc = Nokogiri::HTML(open(url))
name = (doc.at_css("h1").text.split "|")[0]
@model = Model.new
@model.name = name.strip
@almaron
almaron / gist:2695017
Created May 14, 2012 16:50
Error file upload
From params:
#<ActionDispatch::Http::UploadedFile:0x00000003aa01d8 @original_filename="58.png",
@content_type="image/png",
@headers="Content-Disposition: form-data; name=\"bug[screen]\"; filename=\"58.png\"\r\nContent-Type: image/png\r\n",
@tempfile=#<File:/tmp/RackMultipart20120514-17845-2755c4>>
--------------------------------------------------------
In the model:
#--Model
class Forum::Forum < ActiveRecord::Base
#has a field called 'name'
#--Form (in the view)
<%= form_for @forum do |f| %>
<%= f.label :name %>: <%=f.text_field :name %><br />
<%= f.submit "Send" %>
<% end %>
#The Error
ActionView::Template::Error (Infinity):
<div class="forum_right_links">
<% chars = (@topic.forum.tech == 1) ? :owned_real : :active %>
<%= link_to t("forum.links.moderate"), "", :remote => false if user_permitted? :moderate %>
</div>
<%= will_paginate(@posts) %>
<div class="posts_wrap">
<% @posts.each do |post| %>
@almaron
almaron / forum_bug_1.12.204.rb
Created June 15, 2012 13:48
A bug while displaying associated records.
#Forum model
has_many :topics
#Topic model
belongs_to :forum
#forums#show action
def show
@forum = Forum::Forum.find_by_id(params[:id])
@almaron
almaron / forum_show.html.erb
Created June 15, 2012 13:49
View template for the Forums#show action
#show.html.erb
<table class="forum_list" cellpadding="0" cellspacing="0">
<tr class="forum_th">
<th colspan="2"><%= t "forum.lines.topics" %></th>
<th class="forum_posts"><%= t "forum.lines.posts" %></th>
<th class="forum_last_post"><%= t "forum.lines.last_post" %></th>
<% if user_in?([:admins, :masters]) || user_permitted?(:moderate) %>
<th class="forum_admin"></th>
<th class="forum_admin"></th>
<% end %>
@almaron
almaron / gist:2993686
Created June 26, 2012 06:08
Routes.rb
resources :messages, :except => ["index"] do
collection do
get "/inbox", :to => "messages#inbox"
get "/outbox", :to => "messages#outbox"
get "/notify", :to => "messages#notify"
end
end
//View
<%= link_to "Send data", data_request_path, :class => "data_request" %>
//Coffee
$('.data_request').click ->
ref = data_prepare()
$.post {
$(this).attr "href",
<%= f.fields_for :roles do |r| %>
<tr class="form_line">
<td class="form_head">
<%= r.char.name %>
</td>
<td class="char_role_td">
</td>
</tr>
<% end %>