So I am getting the error
NoMethodError in UsersController#show error
undefined method `feed' for nil:NilClass
{"authenticity_token"=>"zalkdfsjfksjd;lfs;lfksdkf/2tPzo=",
"login"=>"session",
"password"=>"admin",
"commit"=>"Log in"}
Why is login being set to "session"? Instead of the real login?
This is my form:
<fieldset>
<div class="yui-g" >
<% form_tag session_path do %>
<p><label class="block" for="login">Login</label>
<%= text_field_tag 'login' %></p>
<p><label class="block" for="password">Password</label>
<%= password_field_tag 'password' %></p>
<!-- Comment this if you don't want this functionality -->
<p><label for="remember_me">Remember me:</label>
<%= check_box_tag 'remember_me' %></p>
<p><%= submit_tag 'Log in', :class => "btn", :id =>
"login_btn" %> <%= link_to "Sign Up", new_user_path %></p>
<% end %>
</div>
</fieldset>
Here are the relevant controllers and models:
Users_Controller:
def show
#...@user = User.find(params[:id])
@user = User.find_by_login(params[:login])
#...@feed_items = @user.feed
@feed_items = @user.feed
end
Users Model:
def feed
#Post.all(:conditions => ["user_id = ?", id])
Post.from_users_subscribed_by(self)
end
Post Model (using SQLite3) :
named_scope :from_users_subscribed_by, lambda { |user|
subscribed_by(user) }
private
# Return an SQL condition for users followed by the given user.
# We include the user's own id as well.
def self.subscribed_by(user)
subscribed_ids = %(SELECT subscribed_id FROM subscriptions
WHERE subscriber_id = :user_id)
{ :conditions => ["user_id IN (#{subscribed_ids}) OR user_id =
:user_id",
{ :user_id => user }] }
end
--
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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.