RailsCasts Pro episodes are now free!

Learn more or hide this

SLB Conseils's Profile

GitHub User: lbstephane

Site: www.slbconseils.fr

Comments by SLB Conseils

Avatar

Just found a solution.

I need to do this

ruby
def authorize
    if current_permission.allow?(params[:controller], params[:action], current_resource)
      current_permission.permit_params! params
    else
            if current_user.nil?
                    redirect_to new_user_session_path
            else
                        redirect_to root_url, alert: "Not authorized."
            end
    end
  end
Avatar

Hi,

Not work for me with rails 4 got a redirect loop :(

Any idea ?

Avatar

I did it like this

confirm: t("sure")

but in fact my question is more for links like the one below :

ruby
<%= link_to (raw('<button class="btn" rel="tooltip" title="Edit"><i class="icol-pencil"></i></button>')), edit_user_path(user)%> 
Avatar

It works like a charm :) Thank you very much !

Just a question, how can I use I18n in javascript confirmation, for example to delete an item

<%= link_to raw(''), user, confirm: 'Are you sure?', method: :delete %>

Thanks :)

Avatar

Hi, nice episode, very helpful.

But (there is always a but lol) i have a problem ! (2 in fact)

I'm using ruby 3.2.11

if I try to use in my routes.rb :

ruby
scope module: :v1, constraints: ApiConstraints.new(version: 1) do

I have an error message 'No route matches [GET] "/dev/v1/media"', if I use a namespace instead (but without constraints) it works! Any idea ? (my first namespace is dev not api)

Other problem, I specified the json format by default in my namespace, set the respond_to :json in my controller but if I use respond_with, got a error message "Missing Template", I need to use :

ruby
@media = Medium.all
              respond_to do |format|
                format.json { render json: @media, status: :created }
        end

Any idea ?

Thanks :)

Avatar

I use the gem s3_direct_upload inspirated by the code, but I have a problem.

Upload and progress bar works perfectly, my problem is :

The url of the uploaded file is a part a a Medium I create. The Medium contain "name", "description", "file_url" etc.

I don't display the S3 form at the creation of my medium, after saving, I redirect_to the Edit action and then display the S3 form to add a file. I tried to set post:media_url(@medium) or post:medium_edit_path(@medium) but it doesn't work cos I guess update require PUT and not POST.

So, is it possible to implement PUT with the gem or may I do something different ?

Thanks for your help

Avatar

Ok adding group_ids as attr_accessible in my User Model solve the problem !

Sorry :p

Avatar

Thanks for this great screencast.

Got an issue with my app.

Checkboxes well diplayed, but when I update, got a message "Can't mass-assign protected attributes: group_ids"

So, I try to manage membership.

Got users and groups.

membership model :

ruby
class Membership < ActiveRecord::Base
  attr_accessible :created_at, :group_id, :position, :user_id
  
  belongs_to :group
  belongs_to :user
  
end

User model :

ruby
  attr_accessible :client_id, :email, :firstname, :group_id, :lastname, :password, :password_confirmation, :role_id
  has_many :memberships
  has_many :groups, :through => :memberships

Group model

ruby
  attr_accessible :name, :client_id, :description, :user_id
  
  has_many :memberships
  has_many :users, :through => :memberships

Here the code in my form

ruby
<%= hidden_field_tag "user[group_ids][]", nil %>
  <% Group.all.each do |group| %>
          <%= check_box_tag "user[group_ids][]", group.id, @user.group_ids.include?(group.id), id: dom_id(group) %>
          <%= label_tag dom_id(group), group.name %><br>
  <% end %>

Did I miss something ?

Thanks

Avatar

It seems the error is generated by the line has_secure_password

My Gemfile is OK, don't understand :(

Edit : Ok, it works, I installed brypt-ruby before, so I needed to update my bundle and restart my server !

Avatar

Got this error on signup
undefined methodkey?' for nil:NilClass`

Any idea ?

Thanks